Page 1 of 1

going from imagick to exec

Posted: 2009-05-13T09:54:35-07:00
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

Re: going from imagick to exec

Posted: 2009-05-13T10:21:54-07:00
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

Re: going from imagick to exec

Posted: 2009-05-13T10:29:09-07:00
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

Re: going from imagick to exec

Posted: 2009-05-13T10:59:45-07:00
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");

Re: going from imagick to exec

Posted: 2009-05-13T11:33:13-07:00
by davidroller
sorry but it's not working i'm getting a blank screen.

Re: going from imagick to exec

Posted: 2009-05-13T11:37:09-07:00
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">

Re: going from imagick to exec

Posted: 2009-05-13T11:56:46-07:00
by davidroller
it gave me :

Code: Select all

<pre>Array
(
)
<br>1<br></pre>

Re: going from imagick to exec

Posted: 2009-05-13T12:56:04-07:00
by fmw42
don't you need to provide the full path to convert (usually /usr/local/bin/convert)?

Re: going from imagick to exec

Posted: 2009-05-13T12:59:30-07:00
by davidroller
no i get the help infos if i just exec(convert)

Re: going from imagick to exec

Posted: 2009-05-13T13:14:49-07:00
by Bonzo
I assume Imagemagick is working; have you just tried a simple convert from one format to another ?

Re: going from imagick to exec

Posted: 2009-05-13T13:20:14-07:00
by davidroller
yes and it works fine

Re: going from imagick to exec

Posted: 2009-05-13T13:25:24-07:00
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/

Re: going from imagick to exec

Posted: 2009-05-13T14:13:47-07:00
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?

Re: going from imagick to exec

Posted: 2009-05-13T14:24:24-07:00
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)

Re: going from imagick to exec

Posted: 2009-05-13T18:03:16-07:00
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!