going from imagick to exec

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
davidroller

going from imagick to exec

Post by davidroller »

Hi, i'm having trouble converting a piece of code of mine from imagick to direct shell input.

could someone help me

the code:

Code: Select all

$im = new Imagick('images/polas.png');

if($_GET[jm]!= "")
{
	$jm = new Imagick('images/sejours/'.$_GET[jm]);
	$jm->resizeImage(160,154,0,0);
	$jm->rotateImage(new ImagickPixel("transparent"),-7);
	$im->compositeImage($jm,Imagick::COMPOSITE_OVER,'83','23');
}

if($_GET[km] != "")
{
	$km = new Imagick('images/sejours/'.$_GET[km]);
	$km->resizeImage(160,154,0,0);
	$km->rotateImage(new ImagickPixel("transparent"),17);
	$im->compositeImage($km,Imagick::COMPOSITE_OVER,'81','211');
}

echo $im;
i'm just in need to make the same thing directly with the shell command

Best regards and thanks for your help, David
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: going from imagick to exec

Post by Bonzo »

I do not use Imagic and so I do not know the commands, what do you want to do?

As I read it:
Get the image name from the URL
Resize the image to 160x154 - keep the aspect ratio or not ?
Rotate the image -7deg with a transparent background
Put the new rotated and resized image over the original at 83 x 23
davidroller

Re: going from imagick to exec

Post by davidroller »

Bonzo wrote:I do not use Imagic and so I do not know the commands, what do you want to do?

As I read it:
Get the image name from the URL
Resize the image to 160x154 - keep the aspect ratio or not ?
Rotate the image -7deg with a transparent background
Put the new rotated and resized image over the original at 83 x 23
it's exactly what i do want to do :) and there a 2 images to insert in the first one.

no aspect ratio kept
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: going from imagick to exec

Post by Bonzo »

Try this and you can modify it for your code if it works:

Code: Select all

exec("convert ( -background none $im -resize 160x154! -rotate -7 ) $jm +swap -geometry +50+50 -composite  output.jpg");
davidroller

Re: going from imagick to exec

Post by davidroller »

sorry but it's not working i'm getting a blank screen.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: going from imagick to exec

Post by Bonzo »

Try this and what do you get:

Code: Select all

$array=array();
echo "<pre>";    
exec("convert ( -background none $im -resize 160x154! -rotate -7 ) $jm +swap -geometry +50+50 -composite  output.jpg 2>&1", $array); 
echo "<br>".print_r($array)."<br>"; 
echo "</pre>";
I assume you have given $im and $jm some values. This will save the image, did you want to do that ? Add a <img src="output.jpg">
davidroller

Re: going from imagick to exec

Post by davidroller »

it gave me :

Code: Select all

<pre>Array
(
)
<br>1<br></pre>
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: going from imagick to exec

Post by fmw42 »

don't you need to provide the full path to convert (usually /usr/local/bin/convert)?
davidroller

Re: going from imagick to exec

Post by davidroller »

no i get the help infos if i just exec(convert)
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: going from imagick to exec

Post by Bonzo »

I assume Imagemagick is working; have you just tried a simple convert from one format to another ?
davidroller

Re: going from imagick to exec

Post by davidroller »

yes and it works fine
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: going from imagick to exec

Post by Bonzo »

The output of the 1 means the image was created you have no errors displayed you can create a simple image. I do not know what else to try.
What version are you using:

Code: Select all

<?php
echo "<pre>";
system("convert -version");  
echo "</pre>";
?> 
Depending how the server is setup Fred you do not always need the user/local/bin/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: going from imagick to exec

Post by fmw42 »

Bonzo wrote:Depending how the server is setup Fred you do not always need the user/local/bin/
Just curious, but what do you need to do to make that happen on a server. On my home Mac, all I need to do is add

export PATH="${PATH}:/Users/fred/Applications/ImageMagick-Scripts/bin"

to my .profile. But I do not know enough about servers and Unix or Windows to know in general what is needed. But I would be interested to know.

Fred

P.S. try adding -compose over just before -composite to be sure it is set properly.

Also I am having trouble with png transparency in IM 6.5.2-4 and getting no transparency effects. see viewtopic.php?f=3&t=13770

Try a simpler composite without the resize and rotate and see if that works.

convert \( -size 100x100 xc:black \) \( -size 50x50 xc:white \) -gravity center -compose over -composite output.jpg

so I suppose in PHP that would be:

exec("convert ( -size 100x100 xc:black ) ( -size 50x50 xc:white ) -gravity center -compose over -composite output.jpg");

Don't know if you need to escape or separately quote the parens in PHP.

I presume you are working on a reasonably modern version of IM. Also have you verified your input images and permission of the images and directory?
Last edited by fmw42 on 2009-05-13T14:25:29-07:00, edited 1 time in total.
davidroller

Re: going from imagick to exec

Post by davidroller »

i'm using the 6.4.8 version on my test computer

Array
(
[0] => Version: ImageMagick 6.4.8 2009-04-28 Q16 http://www.imagemagick.org
[1] => Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
[2] =>
)

and also the 6.2.4 version on the server (can't touch this one)
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: going from imagick to exec

Post by anthony »

fmw42 wrote:
Bonzo wrote:Depending how the server is setup Fred you do not always need the user/local/bin/
Just curious, but what do you need to do to make that happen on a server. On my home Mac, all I need to do is add

export PATH="${PATH}:/Users/fred/Applications/ImageMagick-Scripts/bin"

to my .profile. But I do not know enough about servers and Unix or Windows to know in general what is needed. But I would be interested to know.
Basically you need to also set the PATH environment variable before the web server itself is started, Usually that is done in the server start up scripts. Under UNIX/LINUX the startup script in is something like "/etc/init.d/httpd" On a Mac I have no idea!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply