Auto resizing image based on folder

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
robertsons
Posts: 2
Joined: 2011-10-10T19:42:45-07:00
Authentication code: 8675308

Auto resizing image based on folder

Post by robertsons »

Good Day,

I've been thru some online documentation and WOW image magick is one flexible program with many uses! :P

I couldn't initially determine if i could use it the way i need (so here we are :D) I'd like to know if imagemagick can help with a problem i need to solve.

FOR EXAMPLE:

I have a folder that i drop images into. JPG's, GIF's, PNG's etc
i create a script that's scheduled to run every few minutes. The script run's imagemagick commandline switches and reduces the file size (by shrinking the resolution etc) of any file in that folder.

Does anyone know if imagemagick could operate this way and how i might start to achieve this.

Thanks and regards, Ben Mac.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Auto resizing image based on folder

Post by anthony »

It certainly can. But I would be careful about read/writing some file formats as changes to images can produce accumulative errors and lossy data loss.

I gather this is for avatar, or thumbnail generation of some kind.

Best idea is that new images do to a 'incoming directory' and get processed, to some common format that you are happy with.
Perhaps use some suffix to specify whether the image is a thumbnail. If possible and you have no disk space problems I would keep a copy of the original incoming image, so if you need to you can re-process the image from the original source.

Without more info it is hard to help further.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
robertsons
Posts: 2
Joined: 2011-10-10T19:42:45-07:00
Authentication code: 8675308

Re: Auto resizing image based on folder

Post by robertsons »

Hi Anthony,

Ta for the quick reply,

Yep, well the use of reducing images would be for a few different uses but manyly for reducing images for thumbnails on the net.

We take many photo's for product for that go on the web. Initally the image sizes might be 6MB per image. That is just one example. All images are nearly always JPG.

My idea was possibly have a folder shared on the network and under that root folder have multiple folders with names such as;

1.Originals Images
2.Web Thumbnails
3.Email Ready

The folder name might act has a "profile" (if you will), for determing what would happen to files under those folders.
The scheduled script would convert or reduce the files under the "Web Thumbnails" folder to a specific file dimension and would reduce the contents of the "Email Ready" folder for a nice size ready for email distrubtion (eg. 1024x768, while maintaining original aspect ratio).

I guess i would play around with the specifics with convert etc, BUT i wasn't sure where to put the contents of the ImageMagick-6.6.8-10 directory and how to call all the needed parameters in a .bat script

Hope that makes sense anywayz !!
Cheers Ben.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Auto resizing image based on folder

Post by fmw42 »

You can process (resize) a whole folder of files in one command using mogrify

see
http://www.imagemagick.org/Usage/basics/#mogrify
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Auto resizing image based on folder

Post by anthony »

for thumbnailing see
http://www.imagemagick.org/Usage/thumbnails/

It also goes a bit into mogrify at the start,
though for things beyond simple processing convert in some type of scripted loop tends to be the better choice.

As you plan to generate multiple images of different sizes look at
Writing an Image, Multiple Times
http://www.imagemagick.org/Usage/files/#write

For Windows (.bat) work you may like to look at
Converting Scripts: UNIX Shell to Window DOS
http://www.imagemagick.org/Usage/windows/#conversion
Windows Usage, Batch processing a (sub-)directory tree
http://www.imagemagick.org/Usage/windows/#for_recursive
as well as the other parts of that section.

If you have any problems, ask. We are all very happy to help.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
foruforewer
Posts: 26
Joined: 2011-02-08T04:37:21-07:00
Authentication code: 8675308

Re: Auto resizing image based on folder

Post by foruforewer »

I had http://www.imagemagick.org/Usage/windows/#for_recursive

It is not working for those path having space in it.

Is there any work arround for this?
foruforewer
Posts: 26
Joined: 2011-02-08T04:37:21-07:00
Authentication code: 8675308

Re: Auto resizing image based on folder

Post by foruforewer »

Oh!!! I got answer.. sorry all

FOR /R %1 IN (*.bmp) DO convert "%~f1" "%~dpn1.jpg"
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Auto resizing image based on folder

Post by whugemann »

Correct.

Code: Select all

FOR /R %%a IN (*.tif) DO convert %%a "%%~dna.jpg"
has to be altered to

Code: Select all

FOR /R %%a IN (*.tif) DO imconv "%%~a" "%%~dpna.jpg"
I will correct that with the next update of that webpage.
Wolfgang Hugemann
Post Reply