Page 1 of 1
Auto resizing image based on folder
Posted: 2011-10-10T19:55:21-07:00
by robertsons
Good Day,
I've been thru some online documentation and WOW image magick is one flexible program with many uses!
I couldn't initially determine if i could use it the way i need (so here we are
) 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.
Re: Auto resizing image based on folder
Posted: 2011-10-10T20:03:00-07:00
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.
Re: Auto resizing image based on folder
Posted: 2011-10-10T20:26:57-07:00
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.
Re: Auto resizing image based on folder
Posted: 2011-10-10T21:06:45-07:00
by fmw42
You can process (resize) a whole folder of files in one command using mogrify
see
http://www.imagemagick.org/Usage/basics/#mogrify
Re: Auto resizing image based on folder
Posted: 2011-10-10T22:28:51-07:00
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.
Re: Auto resizing image based on folder
Posted: 2011-10-15T05:06:53-07:00
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?
Re: Auto resizing image based on folder
Posted: 2011-10-15T06:14:13-07:00
by foruforewer
Oh!!! I got answer.. sorry all
FOR /R %1 IN (*.bmp) DO convert "%~f1" "%~dpn1.jpg"
Re: Auto resizing image based on folder
Posted: 2011-10-19T10:18:13-07:00
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.