Jump to content
Sign in to follow this  

passing operators to imagemagick

Recommended Posts



I couldn't seem to find an answer to this, so I'm hoping to get help here.

global $img = ObjCreate("ImageMagickObject.MagickImage.1")

    $NewImage = $img.Convert( _
    "source.JPG", _
    "-gravity", _
    "south", _
    "-background", _
    "#afbc22", _
    "-splice", _
    "0x60", _
    "-font", _
    "OCR-A-Extended", _
    "-pointsize", _
    "12"," "," ", _
    "-annotate", _
    "+0+0", _
    "filename goes here", _

The above script makes use of imagemagick to label an image. So far, so good. However, I have to pass each of the parameters at the time of writing the script. I can use variables and thus change some aspects of the image manipulation, but I cannot, e.g. chose whether to include the setting of the background-colour.

I am looking for a way to dynamicially create the list of parameters and then pass that on to imagemagick. e.g. I want to be able to chose if I write text in one location, or in two separate places.

So, what I need, is some way to pass e.g. an array of arguments to $img.Convert like

$NewImage = $img.Convert($ArrayOfArguments)

I hope I am making myself clear?

Is this possible at all?

Share this post

Link to post
Share on other sites

ETA: I have a very large number of images to work with, so I don't want to generate uncountable,separate DOS-calls etc, when I could just create the object once and have it load the images one after another.

Share this post

Link to post
Share on other sites

Rather than passing the options individually, why can't you just pass it as one string?

Global $img = ObjCreate("ImageMagickObject.MagickImage.1")

$options = ''
$options &= "source.JPG "
$options &= "-gravity "
$options &= "south "
$options &= "-background "
$options &= "#afbc22 "
$options &= "-splice "
$options &= "0x60 "
$options &= "-font "
$options &= "OCR-A-Extended "
$options &= "-pointsize "
$options &= "12 "
$options &= "-annotate "
$options &= "+0+0 "
$options &= "filename goes here "
$options &= "testoutput.jpg"

$NewImage = $img.Convert($options)
Edited by weaponx

Share this post

Link to post
Share on other sites

Hi, thank you for your quick reply.

However, if I try to pass just one string the DLL throws back an unhelpful error-message. (i.e i get the help-file and no actual clue as to where my mistake is.)

It seems to need all the chunks as a comma separated list; I can't pass an array of values, I've tried the "CallArgArray"-Array from the Call function and now I'm just stuck.

I am either looking for the right data type (some kind of object, maybe?) or another way to generate the call I need here.

Share this post

Link to post
Share on other sites

Hi again,

I've still not found a nice solution. However, I am going to use the following trick: I will just prepare the function call with the largest number of parameters I might possibly need and then, for each individual call, feed imagemagick with redundant arguments - e.g. set the background color multiple times.

That way, I should manage to use just two calls, one with an even and one with an uneven number of arguments that I can then generate dynamicially. Hopefully, setting the colour will not take too much processing time ...

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this