Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-10-07 13:57:37

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Thumbnail processing en-masse

Say I want a directory structure like this:

images
    main
        00
            123837.jpg
            938451.jpg
            328564.jpg
            ...
        01
            95643.jpg
            234111.jpg
            4933.jpg
            ...
        02
            ...
    thumb
        00
            123837.jpg
            938451.jpg
            328564.jpg
            ...
        01
            95643.jpg
            234111.jpg
            4933.jpg
            ...
        02
            ...

I have the main path all set up and populated with a few hundred thousand product images (all of varying dimensions), spread across the subdirs using an algorithm to keep the number of files per directory manageable. Now I want to create the corresponding thumbnails. Are there any (preferably freeware) tools that’ll let me batch convert them into neat image tiles subject to the following rules:

  1. Resize to fixed dimensions (e.g. 300×300), AND
  2. … maintain original aspect ratio, AND
  3. … if the image is smaller, don’t upscale it, AND
  4. … any image that is smaller than, or of the wrong aspect ratio compared with, the desired dimensions the canvas should be padded to the thumb dimensions with a given background colour (e.g. white), AND
  5. … write the thumbs in the thumb directory, mimicking the directory structure of the main tree.

I’ve tried a tonne of tools so far and nothing does it all. The closest tool I’ve found is IrfanView. You can put it in Thumbnails mode, pick your directory, set the canvas padding, aspect, upscaling rules, dimensions and so forth, then say “Save selected thumbs as images”. But it only outputs all thumbs into a single directory.

Conversely, it has a great batch image processing tool which will allow resizing, maintain aspect ratio, set upscaling rules, dimensions, etc and will output to a directory of your choice mimicking the input subdirectory structure. But it doesn’t do the canvas resizing, so the pics only get resized in one dimension and don’t get the background applied if they’re too small. Grrr.

Anyone know of anything that’ll do what I want, or do I need to write a script to go through each subdir and find a way to call the Irfanview Thumb processor on each one from the command line? Thanks for any ideas.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#2 2015-10-07 14:10:08

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Thumbnail processing en-masse

ImageMagick perhaps?
Have you considered writing a script that generates the thumbs when requested and then caches the result (if it doesn’t exist, let the 404-handler generate the thumb)?

Offline

#3 2015-10-07 14:35:53

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Thumbnail processing en-masse

ruud wrote #295460:

ImageMagick perhaps?

How did I miss that one? I’ll give it a go, thanks.

Have you considered writing a script that generates the thumbs when requested and then caches the result (if it doesn’t exist, let the 404-handler generate the thumb)?

That was Plan C, yes, after A) tool to generate them in one go, B) script to iterate the folders and generate them in one go. As long as I could figure out a way to do the requisite decision making, scaling, and canvas resizing in GD.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2015-10-07 18:55:47

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 259
Website

Re: Thumbnail processing en-masse

On Mac, you could use Automator / Applescript to build a suitable workflow.

Offline

#5 2015-10-07 20:06:32

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: Thumbnail processing en-masse

It’s not free (10$) but you might want to try PhotoMill. It has a fully functional 7 day trial that you can test with. It has an amazing number of settings and think it does 1, 2, 4, and 5. You might be able to do 3 by using the group function of the browser to first filter out the images that are smaller by size, then use two operations… (Manual here). You can save your settings as presets too. Also if you have a ton of images, you might want to run imageoptim once you have completed the operation…


TXP Builders – finely-crafted code, design and txp

Offline

#6 2015-10-08 01:32:13

hcgtv
Plugin Author
From: Key Largo, Florida
Registered: 2005-11-29
Posts: 2,722
Website

Re: Thumbnail processing en-masse

ruud wrote #295460:

ImageMagick perhaps?

That’s a good choice, el command line never fails.

Also check out the XnView family of tools, lot’s of batch processing goodies.

Offline

#7 2016-06-16 18:12:25

lazlo
Member
Registered: 2004-02-24
Posts: 110

Re: Thumbnail processing en-masse

Bloke
Did you solve this with ImageMagick?
Does it happen server side?
User uploads an image and a thumbnail is created in the thumbnail directory?

Can you share your answer?

Offline

#8 2016-06-16 22:28:26

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Thumbnail processing en-masse

lazlo wrote #299786:

Did you solve this with ImageMagick?

I downloaded ImageMagick and toyed with it a bit, then other priorities overtook the image wrangling (like, designing the DB schema, coding the sites, and taking new product photos). Two out of three of those are approaching completion so I’ll be doing the image conversion within the next month. So, unfortunately, nothing to report at the moment.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#9 2016-06-16 22:52:40

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 329
Website

Re: Thumbnail processing en-masse

I’ve used ImageMagick for years. It can do a lot of amazing things. We use it on a cron schedule (hundreds of times a day, 24 × 7) to process images not related to Textpattern uploads, but it can do many of the things on your list Bloke.

The directory structure isn’t an ImageMagick thing (as I understand it), but there’s no reason you couldn’t program a shell script to create that and then have ImageMagick perform its magic within that structure.

It can be coded to respect original aspect ratio. It can be coded to force a new aspect ratio. It can crop and resize like crazy.

If I can help, reach out. Your cool code and plugins have sure helped me over the years.

Offline

#10 2016-06-17 17:35:25

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Thumbnail processing en-masse

Thanks, I may well come knockin’!


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB