Need some help perfecting IM as a script

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?".
SoCal Waite
Posts: 9
Joined: 2014-11-07T19:56:50-07:00
Authentication code: 6789

Need some help perfecting IM as a script

Post by SoCal Waite »

I am pretty new to IM, I have a little experience, but it is mainly simple scripts. I have some ideas on image development through IM, but execution is where I fall short.

If you are feeling charitable and have 20-30 minutes to burn with me on Skype IMing or even a phone call please let me know. My Name is Ryan.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need some help perfecting IM as a script

Post by fmw42 »

I moved your post here, because the Consulting Forum is only for paid consulting.

If you post an example (you can upload to dropbox.com and put URLs here) and your command lines and explain your problem, then you likely will get free help here. If someone wants to follow up with your privately, they can send you PM on the forum. You can go from there.

Also whenever you post a problem, please identify your version of IM and platform.
SoCal Waite
Posts: 9
Joined: 2014-11-07T19:56:50-07:00
Authentication code: 6789

Re: Need some help perfecting IM as a script

Post by SoCal Waite »

Thanks.

I think I am using IM a little bit differently than most on here, hence my lack of example. But Let me give his a shot.

First I am trying to put a fixed size text image on top of several different size pictures. I have hundreds of images that are all different sizes, from 450x300 to 2500x1500. I need to find the "key" to auto re-sizing the text image to better fit the base image. So that its legible in the bigger pictures and doesn't go out of the frame in the smaller ones.

Here is the script I am using currently (the {FOLDER05} contains the images and {FOLDER10} has the text images):

C:\ImageMagick\convert.exe "{FOLDER05}" -gravity Center -geometry +0+0 -composite -size Fit "{FOLDER10}" -gravity North -composite "{Output_File}"
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Need some help perfecting IM as a script

Post by Bonzo »

I need to find the "key" to auto re-sizing the text image to better fit the base image. So that its legible in the bigger pictures and doesn't go out of the frame in the smaller ones.
I am afraid this does not make sense to me: You have a text image, base image, small image and large image?

An example or a diagram is always helpful.
SoCal Waite
Posts: 9
Joined: 2014-11-07T19:56:50-07:00
Authentication code: 6789

Re: Need some help perfecting IM as a script

Post by SoCal Waite »

So the "Visit us at" text in both images is a .png overlay. I have several of them and they are all the same size. I have hundreds of bed pictures that are all different sizes, and I need to keep them in their original size.

I need IM to re-size the text images to fit the bed pictures.

Image
Image

I know that I can re-size the bed pictures to the same size so that they are uniform to overlaying the text image, but that is hurting my sales campaign now.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Need some help perfecting IM as a script

Post by Bonzo »

I only really know php syntax and do not know the language you are using but something like this should work:

Get the image width ( using -ping speeds up the process as not all the image data is read )

Code: Select all

identify -verbose -ping -format "%[fx:w]" bed.jpg
If you read that into a variable lets call it WIDTH you should be able to use

Code: Select all

convert bed.jpg \( text.png -resize WIDTHx \) -gravity north -composite output.jpg
You may need to use ( ) not \( and \) and in php I would put {WIDTH}x
SoCal Waite
Posts: 9
Joined: 2014-11-07T19:56:50-07:00
Authentication code: 6789

Re: Need some help perfecting IM as a script

Post by SoCal Waite »

I am using windows Dos commands to use IM. It is hard to convert from PHP, I will see if I can find a way to translate.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Need some help perfecting IM as a script

Post by Bonzo »

The above should have been Imagemagick syntax; try this to get the variable:

Code: Select all

:: Set the variable width to the image width
    For /F %%# in ('identify -verbose -ping -format "%%[fx:w]" "%1"') Do (SET /A "width=%%#")
It has been a long time since I wrote the batch file this came from and I can not remember what it means!
It comes from some batch scripts I have on my site: http://www.rubblewebs.co.uk/imagemagick/batch.php
SoCal Waite
Posts: 9
Joined: 2014-11-07T19:56:50-07:00
Authentication code: 6789

Re: Need some help perfecting IM as a script

Post by SoCal Waite »

Trying to decipher this, and here is what I came up with:

C:\ImageMagick\convert.exe ^('identify -verbose -ping -format "%%[fx:w]" "{FOLDER05}"'^) -gravity Center -composite "{FOLDER10}" -resize ^(SET /A "width=%%#"^) -gravity North -composite "{Output_File}"

But this to doesn't work, and my head hurts.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Need some help perfecting IM as a script

Post by Bonzo »

Looks like we both know about the same amount of Dos/Batch.

Try this

Code: Select all

:: Does just the one file
For /F %%# in ('identify -verbose -ping -format "%%[fx:w]" "%1"') Do (SET /A "width=%%#")
C:\ImageMagick\convert.exe bed.jpg ( %1 -resize width ) -gravity North -composite "th_%~n1.png"
Depending how you setup imagemagick you should be able to use convert and identify rather than C:\ImageMagick\identify.exe and C:\ImageMagick\convert.exe
I do not think you need to escape the ( but am not sure.

I would hard code some images to get the code working and then put in the folders when the Imagemagick code is working. Also you will either need to write a loop to get the file names or use something different to convert which I can not remember. There have been other questions about looping over files posted in the last couple of months.
SoCal Waite
Posts: 9
Joined: 2014-11-07T19:56:50-07:00
Authentication code: 6789

Re: Need some help perfecting IM as a script

Post by SoCal Waite »

Would be this be the correct string?

('identify -verbose -ping -format "%%[fx:w]" "{FOLDER05}"') "{FOLDER05}" -composite "{FOLDER10}" (SET /A "width=%%#") -gravity North -composite "{Output_File}"

Sorry for not understanding this better, I am not a programmer, I am in a little over my head.
SoCal Waite
Posts: 9
Joined: 2014-11-07T19:56:50-07:00
Authentication code: 6789

Re: Need some help perfecting IM as a script

Post by SoCal Waite »

Here is another idea that I just had, I can easily resize the pictures to correctly fit the "banner", and then resize the output file to fit randomly within a variable. Would this be any easier?
SoCal Waite
Posts: 9
Joined: 2014-11-07T19:56:50-07:00
Authentication code: 6789

Re: Need some help perfecting IM as a script

Post by SoCal Waite »

Guys I had to get some local help to understand what my issue was. Thank you so much for your help. My issue was that I am using IM inside WinAutomation, and that is why you guys weren't understanding my code (part of the script) and I wasn't understanding your because I had never used CMD to test it before. Like I said, I am pretty new to this.

I wound up resizing the bed pictures to a common size then using a draw command to write what I wanted on them, then again resizing the images on the output to random sizes. Its not a perfect solution, but it works for me.

Now I just need a list of the fonts that IM supports. Going to go dig & see if I can find it
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need some help perfecting IM as a script

Post by fmw42 »

convert -list font will show you what fonts IM knows about. You can edit your type.xml file to put in other fonts. Or run this perl script to do that automatically. see http://www.imagemagick.org/Usage/script ... k_type_gen

True Type Fonts (ttf)
Ghostscript Fonts (afm)
Open Type Fonts (otf)
SoCal Waite
Posts: 9
Joined: 2014-11-07T19:56:50-07:00
Authentication code: 6789

Re: Need some help perfecting IM as a script

Post by SoCal Waite »

My head is hurting again. I tried the convert -list font and got a mile long list of fonts that I could only see about 1/16th of once it finished. Now I found a picture that someone posted with a list of fonts that IM supposedly recognizes. However about 1/3rd of that list breaks the job.

From many hours of reading and a bottle of asprin, I have concluded that I have to tell IM to pull all the fonts into one place, but for the life of me I can't figure out how to do this from CMD. Again, sorry for not comprehending this better, programming is not my thing, I just have to take up the slack for a while.
Post Reply