Page 1 of 1

batch convert

Posted: 2017-02-01T09:45:03-07:00
by Natul
Hi,
I try to convert and create a new image with suffix " _web" for many images in folders and subfolders

example i have this folders

c:\test\
c:\test\myimage\image.jpg
c:\test\allimages\myimages.jpg

i try to use this
c:
cd c:\test
FOR /R %%a IN (*.jpg) DO convert %%a -resample 72 -units pixelsperinch -colorspace RGB -set filename:original %%t_web.jpg %%[filename:original]


the script work, but put all "_web" images in a main directory c:\test

how to save the image _web in a right folder?

to have this
c:\test\
c:\test\myimage\image.jpg
c:\test\myimage\image_web.jpg
c:\test\allimages\myimages.jpg
c:\test\allimages\myimages_web.jpg

thanks!!

Re: batch convert

Posted: 2017-02-01T10:05:01-07:00
by fmw42
In your convert command, you must tell IM where to find the input image and where to put the output image. You can get all images from one directory and put them into separate directories, but you must tell IM which subdirectory to use for each output image. Are all your input images coming from the parent test directory?

Note you can process all images in a given directory using mogrify.

Why are you converting to colorspace RGB? Are you on a very old version of IM when RGB and sRGB were swapped? Currently RGB is linear and sRGB is non-linear and what most people expect to see.

Re: batch convert

Posted: 2017-02-01T15:09:20-07:00
by snibgo
Natul wrote:how to save the image _web in a right folder?
You can include a folder (aka directory) name in the output filename. This could be %d -- see http://www.imagemagick.org/script/escape.php

Or you could do it with the Windows mechanism: %%~dpa

Re: batch convert

Posted: 2017-02-02T05:06:10-07:00
by Natul
ok, I realized that the problem is that I do not set the correct IM in output subfolders.

I dont understand how I can add this information to my script? to save converted image " _Web" in the correct subfolder?

sorry I am beginner to IM

thanks

Re: batch convert

Posted: 2017-02-02T07:35:24-07:00
by snibgo
I pointed you to documentation http://www.imagemagick.org/script/escape.php . That shows you that %t is "filename without directory or extension (suffix)". It also shows you that %d is "directory component of path". In Windows BAT, you need to double the % signs. For IM, I think a backslash here also needs to be doubled. So try using "%%d\\%%t" instead of "%%t".

Re: batch convert

Posted: 2017-02-02T09:02:49-07:00
by Natul
ok work! with %%d\\%%t thank you!!!

Re: batch convert

Posted: 2017-02-11T05:58:49-07:00
by Natul
I have another question,

this script work but only if i dont have a space in a name of folders or files.


FOR /R %%a in (*.jpg) DO convert %%a -resample 72 -units pixelsperinch -colorspace RGB -set filename:original %%d\\%%t_web.jpg %%[filename:original]

where i put the " " to use it when i have a space in folders name or files?

thanks!!!

Re: batch convert

Posted: 2017-02-11T06:55:41-07:00
by GeeMack
Natul wrote: 2017-02-11T05:58:49-07:00this script work but only if i dont have a space in a name of folders or files.

FOR /R %%a in (*.jpg) DO convert %%a -resample 72 -units pixelsperinch -colorspace RGB -set filename:original %%d\\%%t_web.jpg %%[filename:original]

where i put the " " to use it when i have a space in folders name or files?
I would start by putting doublequotes around the first use of the variable "%%a" after "convert", and around the filename where you set it in the command, and around the filename where you use it at the end of the command.

Code: Select all

FOR /R %%a in (*.jpg) DO (
   convert "%%a" -resample 72 -units pixelsperinch -colorspace RGB ^
   -set filename:original "%%d\\%%t_web.jpg" "%%[filename:original]"
)