Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We recently decided to redesign our old app which used 150x150 thumbnails. New thumbs are of size 250x250.

Now what i have to do is an one-off process to replace all the old 150 thumbs that were created before the redesign, with 250 ones.

The function used for creating new thumbnails was php's imagecopyresampled. I would like to find something that would give me similar/same results.

imagecopyresampled() copies a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity.

Also, the job itself is a little complicated since there are some folders/files that has to be excluded when iterating trough the files.


level 1: company folder
level 2: company property folder, company products folder
level 3: there are images that have to be resized inside company property folder.

Structure sample:

company 1
company 2
company 3
----company 3 property
--------image1.jpg (original size)
--------image1_thumb.jpg (old 150 thumb)
----company 3 products (folder also includes images but they should not be resized)

Basically the only files we work with are original-sized images (ones without _thumb) inside property folders. Old 150px thumb images are to be deleted and/or replaced by new, 250px ones.

share|improve this question

closed as too broad by Nifle, Mokubai, mpy, Shekhar, Ƭᴇcʜιᴇ007 Aug 31 '13 at 15:45

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 1 down vote accepted

As FvD says, ImageMagick is very good for resizing images.

For finding all the relevant files and having convert process them, I would suggest installing findutils, or even better MSYS, because the latter not only includes findutils but a whole lot of other goodies (like a proper shell) as well.

If you have Python installed, you could write a simple program that uses os.walk() to travel a file system tree and use to convert the file.

A partial example;

import os
import subprocess

for root, dirs, files in os.walk('company 3\company 3 property'):
    images = [os.path.join(root, f) for f in files if f.endswith('.jpg') and not '_thumb' in f]
    for f in images:
        outbase = f[:-4] # simply remove '.jpg'
        out = outbase += '_thumb.jpg'
        args = ['convert', f, '-scale', '250x250', out]

Edit: If you have a directory that you don't want to visit, just remove it from the dirs dictionary. See the documentation for os.walk().

share|improve this answer
I decided to use a Wand for image transformation. I will accept this answer because it gave me an idea how to start, but does not completely solve my question since there are more levels of folders to loop through, not only one like in your example. Also there are some folders that should be excluded from the loop. I described the problem to you here… – Biker John Aug 25 '13 at 16:41
@BikerJohn You can skip directories in os.walk. See edited answer. – Roland Smith Aug 25 '13 at 17:06

you can set up the traversal through the folders with anything you like. The conversion is best done with ImageMagick that works greate from the commandline or embedded into anything else.

The particular magic you are looking for is under convert.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.