trying to make a simple bulk image program having issues

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
guitarist24000
Posts: 3
Joined: 2011-10-21T07:18:05-07:00
Authentication code: 8675308

trying to make a simple bulk image program having issues

Post by guitarist24000 »

The idea of my program is to take all the pictures in one folder and apply the following
First expand the image canvas vertically with a white background
From there it should then put the specified text in every corner

however my code isn't working and probably has errors all over it, Im using windows command prompt to run it with a batch file

here is my code:

Code: Select all

cd "C:\Users\Gregg\Desktop\imagemagick portable\ImageMagick-6.7.3-1"
mogrify.exe -background white -extent 110% -gravity center C:\Users\Gregg\Desktop\testimages\*  \
mogrify.exe	    -gravity SouthWest -draw "text 10,10 'Sales@alltest.net'" \
mogrify.exe	    -gravity NorthWest-draw "text 10,10 'Alltest Instruments'" \
mogrify.exe          -gravity SouthEast -draw "text 10,10 '(123) 456-7890'" \
mogrify.exe	    -gravity NorthEast -draw "text 10,10 'Express Test'"
pause
this is my fist time using imagemagick, I'm very used to ifranview but unfortunately ifranview cant accomplish what I want. Can anyone help me make my code properly work?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: trying to make a simple bulk image program having issues

Post by fmw42 »

you have to cd to the directory you want to process the images or put the full path to that directory in each of your mogrify commands. However, doing so will write over each of your original images. You may be safer using a different output directory using the -path option.

see
http://www.imagemagick.org/Usage/basics/#mogrify
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: trying to make a simple bulk image program having issues

Post by Bonzo »

I would probably use convert and do the file selecting in the batch script. I am not a batch script expert and have a couple of scripts on my site I have written and one from someone else that will probably help you out.

Batch script example page

I think you can do eveything you want done with Imagemagick in one convert line; something like:

Code: Select all

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

:: Read all the jpg images from the directory, vertical extent, add some text and save as a png in a different directory
for %%f in (%1\*.jpg) do ( convert "%%f" -background white -gravity center -extent x110% ^
 -fill black ^
 -gravity SouthWest -annotate +10+10 "Sales@alltest.net" ^
 -gravity NorthWest -annotate +10+10 "Alltest Instruments" ^
 -gravity SouthEast -annotate +10+10 "(123) 456-7890" ^
 -gravity NorthEast -annotate +10+10 "Express Test" ^
 "%2\%%~nf.png" )
Thinking about it there may be a problem with the -gravity in the extent messing up the gravity for the text - hopefuly this problem will be sorted in version 7. You may have to save an intermediatry image.

Run method in command line:

Code: Select all

name_of_script "path to read images from" "path to save images to"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: trying to make a simple bulk image program having issues

Post by fmw42 »

as long as the gravity is reset after the -extent, it should be fine, as far as I know.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: trying to make a simple bulk image program having issues

Post by Bonzo »

Just had a play with this and could not get it to work. I formated my PC last week and the only photos I had were the Windows sample ones and after about an hour of failing I uploaded a photo of my own to try and it worked! For some reason I could not modify the Windows sample photos.

Anyway seems to work just need to escape the % in 110% so it becomes 110%%

The font size could be a problem if you are working in percentages for the image size.
guitarist24000
Posts: 3
Joined: 2011-10-21T07:18:05-07:00
Authentication code: 8675308

Re: trying to make a simple bulk image program having issues

Post by guitarist24000 »

Bonzo wrote:I would probably use convert and do the file selecting in the batch script. I am not a batch script expert and have a couple of scripts on my site I have written and one from someone else that will probably help you out.

Batch script example page

I think you can do eveything you want done with Imagemagick in one convert line; something like:

Code: Select all

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

:: Read all the jpg images from the directory, vertical extent, add some text and save as a png in a different directory
for %%f in (%1\*.jpg) do ( convert "%%f" -background white -gravity center -extent x110% ^
 -fill black ^
 -gravity SouthWest -annotate +10+10 "Sales@alltest.net" ^
 -gravity NorthWest -annotate +10+10 "Alltest Instruments" ^
 -gravity SouthEast -annotate +10+10 "(123) 456-7890" ^
 -gravity NorthEast -annotate +10+10 "Express Test" ^
 "%2\%%~nf.png" )
Thinking about it there may be a problem with the -gravity in the extent messing up the gravity for the text - hopefuly this problem will be sorted in version 7. You may have to save an intermediatry image.

Run method in command line:

Code: Select all

name_of_script "path to read images from" "path to save images to"

Im sorry one last question, what do I use to run this properly

I created the file and named it "watermark" with no extension, put it on the desktop, and to tried calling it in cmd I said

Code: Select all

watermark "C:\Users\Gregg\Desktop\testpics" "C:\Users\Gregg\Desktop\testpics\watermarked"
should my command be something like

Code: Select all

mogrify.exe -"C:\Users\Gregg\Desktop\watermark" "C:\Users\Gregg\Desktop\testpics" "C:\Users\Gregg\Desktop\testpics\watermarked"
?

Thank you for any help your able to give
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: trying to make a simple bulk image program having issues

Post by Bonzo »

I wonder if I had another problem as I found the batch file in the c folder.

I gave the file a .bat extension and ran it using:

Code: Select all

test.bat "C:\Users\Anthony\Pictures\TEST" "C:\Users\Anthony\Pictures\TEST"
guitarist24000
Posts: 3
Joined: 2011-10-21T07:18:05-07:00
Authentication code: 8675308

Re: trying to make a simple bulk image program having issues

Post by guitarist24000 »

Okay problem... nothing happens, I tried running it in windows 7 and windows xp

my exact file is:

watermark.bat

Code: Select all

::Turn of displaying the code on the screen
@echo off
:: Read all the jpg images from the directory, vertical extent, add some text and save as a png in a different directory
for %%f in (%1\*.jpg) do ( convert "%%f" -background white -gravity center -extent x110%% ^
-fill black ^
-gravity SouthWest -annotate +10+10 "Sales@alltest.net" ^
-gravity NorthWest -annotate +10+10 "Alltest Instruments" ^
-gravity SouthEast -annotate +10+10 "(732) 123-1234" ^
-gravity NorthEast -annotate +10+10 "Express Test" ^
"%2\%%~nf.png" )
pause
and the exact command I'm running is:

Code: Select all

watermark.bat "C:\Documents and Settings\XPMUser\Desktop\testimages" "C:\Documents and Settings\XPMUser\Desktop\testimages\watermarked"
I put a pause at the end of the batch file to try to troubleshoot, but it doesn't even pause. Any ideas as to what the problem is? I know for a fact Imagemagick is installed properly and works from command line.



edit:: nvm I fixed it by putting everything on one line in the batch file, now its running properly
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: trying to make a simple bulk image program having issues

Post by fmw42 »

doesn't mogrify require an * as the filename

see
http://www.imagemagick.org/Usage/basics/#mogrify
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: trying to make a simple bulk image program having issues

Post by Bonzo »

The new lines after the ^ need to start with a space and for some reason the code when posted above automaticaly stripped it out!
Post Reply