Still in editing – How to replace images of a wordpress blog in bulk on OS X and Linux systems

I need to replace all non-square pictures of a WordPress WooCommerce shop by square versions for design reasons.

To do so I follow these asghhgfdsasdfghj steps:

  1. Download all images using an ftp-client.

    The pictures are located in a folder as follows:

    http://www.placeofyourWP-Installation.com/wp-content/uploads

    You will find them in a folder structure of years and months. Simply Download the all years folders from the uploads folder and save them to a dedicated folder (to_edit e.g.).

  2. Get rid of all preview versions.

    WordPress adds previews named as follows to the original version:

    origfilename-150x150.jpg

    You will find quite a lot of different sizes.

    Use your command line (Terminal on Mac OS systems e.g.) and go to the folder you put all the years folder in using commands as follows:

    To list your directory’s content use

    ls

    To enter a subfolder use

    cd nameofthesubfolder

    Or simply enter the whole path to your target folder if you already know it, like

    cd first_level/second_level/third_level/target_folder

    Delete all previews in all subfolders using this command:

    find . -name \*150x150* -type f -delete
    • You need to replace the 150×150 with the sizes of your previews given.
    • -type f searches for files only
    • -delete will delete the files found – if you want to check first, what will be deleted, run the command without the -delete to get a list

    Repeat this with other resolutions you’d like to delete until you have no more left then your original image files.

  3. Replace all non-square images by their square versions.

    You do this using this command:

    sips
  4. Upload the new versions in the exact order of the original file system.

    As you made sure in the step before, all images still have the same name like their non-square predecessors and are still stored on the very same place in the file system as before you simply upload and replace all year folders in the upload folder on your webspace.

  5. Rebuild all previews

    You can easily do so using a WP plugin like AJAX Thumbnail Rebuild.

    Just install it and find it in tools section to run it.

Ressources I used to learn this:

http://superuser.com/questions/112078/delete-matching-files-in-all-subdirectories

http://www.computerhope.com/unix.htm

http://cactuslab.com/imagemagick/

https://developer.apple.com/library/mac/documentation/OpenSource/Conceptual/ShellScripting/Introduction/Introduction.html#//apple_ref/doc/uid/TP40004268-TP40003516-SW1

Leave a Reply

Your email address will not be published. Required fields are marked *

seventeen − 7 =