batch convert

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
Natul
Posts: 6
Joined: 2017-02-01T09:38:28-07:00
Authentication code: 1151

batch convert

Post 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!!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: batch convert

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: batch convert

Post 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
snibgo's IM pages: im.snibgo.com
Natul
Posts: 6
Joined: 2017-02-01T09:38:28-07:00
Authentication code: 1151

Re: batch convert

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: batch convert

Post 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".
snibgo's IM pages: im.snibgo.com
Natul
Posts: 6
Joined: 2017-02-01T09:38:28-07:00
Authentication code: 1151

Re: batch convert

Post by Natul »

ok work! with %%d\\%%t thank you!!!
Natul
Posts: 6
Joined: 2017-02-01T09:38:28-07:00
Authentication code: 1151

Re: batch convert

Post 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!!!
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: batch convert

Post 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]"
)
Post Reply