(newbie)need a automated bat file but stuck.

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
ricky ricardo

(newbie)need a automated bat file but stuck.

Post by ricky ricardo »

Hope somebody can help me out on something
I have 2 folders that have images.
folder 1 has 496 x 720 images
folder 2 has the 1280 x 720 images
so i used -gravity west -composite on 1 named image and it works but how do i automate it without using names of that image?

I want every image off folder 2 to get the image from folder 1 making the new image in folder 2.

Hope somebody can help me out on this

EXAMPLE:

Code: Select all

convert.exe pictures/folder2/8738843.jpg pictures/folder1/8738843[LEFTSIDE].png -gravity west -composite 8738843.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: (newbie)need a automated bat file but stuck.

Post by fmw42 »

I think you need to use full paths from c:\ and use backslashes (unless you are using cygwin-like unix). I am not a windows user, so any Windows expert, please correct me.

P.S. there is no such thing as [LEFTSIDE] in IM. You will need to find the [WidthxHeight+xoffset+yoffset]
see selecting an image region at http://www.imagemagick.org/script/comma ... essing.php
or
-crop at http://www.imagemagick.org/script/comma ... s.php#crop
or http://www.imagemagick.org/Usage/crop/#crop_repage
ricky ricardo

Re: (newbie)need a automated bat file but stuck.

Post by ricky ricardo »

hey thnx for the reply but im using windows
&[LEFSIDE].png is the name off the imagefile and when using gravity west the image is the way i want it.
I only need it for more images really.
so something recursive but how? & keeping the name.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: (newbie)need a automated bat file but stuck.

Post by fmw42 »

sorry i am not a Windows user
ricky ricardo

Re: (newbie)need a automated bat file but stuck.

Post by ricky ricardo »

thats a shame but how will i go about it on unix?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: (newbie)need a automated bat file but stuck.

Post by fmw42 »

you will need to write a loop over each image name found in both folders and composite them together into one or the other folder or even a different folder. The unix command will not look anything like what you do in DOS, so perhaps some Windows user can come to your rescue.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: (newbie)need a automated bat file but stuck.

Post by Bonzo »

I had a go at batch files last year but have basicly forgotten most of it as I only use a simple file myself.

This may help you out:

Code: Select all

::Modify a whole directory of images
::Read a directory and modify all jpg images

::Turn of displaying the code on the screen
@echo off

:: Read all the jpg images from the directory, resize them, add some text and save as a png in a different directory
for %%f in (%1\*.jpg) do ( convert %%f -resize 200x200 -pointsize 18 -fill black ^
-gravity northwest -annotate +0+0 "Some text" "%2\%%~nf.png" )

::This batch file was named resize.bat and called using "resize path\to\original\ path\to\save"

Some other examples: http://www.rubblewebs.co.uk/imagemagick/batch.php

You should be able to make your batch file from the examples here.
ricky ricardo

Re: (newbie)need a automated bat file but stuck.

Post by ricky ricardo »

Big Thnxx but then my newbie side will pop up.

I dont need any risizing so i can remove the parts?

Am i In the right direction?

Code: Select all

::Modify a whole directory of images
::Read a directory and modify all jpg images

::Turn of displaying the code on the screen
@echo off

:: Read all the jpg images from the directory, resize them, add some text and save as a png in a different directory
for %%f in (%1\*.jpg) do -gravity west -annotate +0+0 "" "%2\%%~nf.png" )

::This batch file was named resize.bat and called using "resize path\to\original\ path\to\save"
ricky ricardo

Re: (newbie)need a automated bat file but stuck.

Post by ricky ricardo »

let me say it different.

i get the gravity part but cant get the right directories & where i put it on you're example.

::pictures/folder2/8738843.jpg
::pictures/folder1/8738843[LEFTSIDE].png

-gravity west -composite 8738843.jpg

but need to add a bat file on folder1 & folder 2?
hope you can help me out because doing this manual will take like forever
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: (newbie)need a automated bat file but stuck.

Post by Bonzo »

Yes you can change the convert part to what you want.

From memory to run my example posted you need to:

Name the file resize.bat and save it on your desktop
Find the path to the images to modify e.g. C:\Users\Anthony\Pictures
Find the path to save to e.g. C:\Users\Anthony\Pictures\modified
Open up the comand prompt and input: resize C:\Users\Anthony\Pictures C:\Users\Anthony\Pictures\modified

The last example on my site is anotherway of doing it but you need to setup some paths etc. in the bat file.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: (newbie)need a automated bat file but stuck.

Post by Bonzo »

I have just tried this code and there seems to be some problems. For a start the convert is missing and it will not run on Vista.
I am afraid that I do not have time to look into it at the moment.
ricky ricardo

Re: (newbie)need a automated bat file but stuck.

Post by ricky ricardo »

I got this but it gives a error

convert:missing an image filename

Code: Select all

for %%f in (pictures\folder2\%1\*.jpg) do (convert %%f ^
-gravity west -composite -annotate +0+0 "" "pictures\folder1\%2\%%~nf[LEFTSIDE].png" )

PAUSE
it scans...
so one step closer but it needs to replace the folder2 images but convert:missing an image filename are some off the errors i get
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: (newbie)need a automated bat file but stuck.

Post by el_supremo »

Try this:

Code: Select all

::Modify a whole directory of images
::This assumes that you are in the directory pictures\folder2 so you only have to specify the
:: path to folder1. The result will be in folder2. 
:: Name this batch file as resize.bat and call it using "resize path\to\folder1"
:: For example, if you are in folder2 you could use "resize ..\folder1"

::Turn off displaying the code on the screen
@echo off
for %%f in (*.jpg) do ( convert "%%f"  "%1\%%~nf[LEFTSIDE].png" -gravity west -composite "%%~nf.png" )
Pete
ricky ricardo

Re: (newbie)need a automated bat file but stuck.

Post by ricky ricardo »

ohh yess it worked so thnx all for helping me out on this!!!
Post Reply