Can my complex actions be done with IMagick?

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
hknight
Posts: 32
Joined: 2007-08-02T10:16:15-07:00

Can my complex actions be done with IMagick?

Post by hknight »

Hello,

I do some really funky things with ImageMagick, thanks to some help from Anthony.

For example, to add a gradient to a button I have to use ImageMagick to calculate the size of the button, write that size to a text file, then read that text file later.

Can this be done with IMagick?

Please review the file attachment and tell me if this can be done STRICTLY with IMagick, without the use of exec().

Thanks!
Attachments
button.zip
Complex ImageMagick Code
(1.5 KiB) Downloaded 1975 times
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Can my complex actions be done with IMagick?

Post by mkoppanen »

Yes, I took a quick look and it looks doable.

Heres an example of a little more complicated drawing operation using imagick:

http://phpfi.com/259259

--
Mikko Koppanen
Mikko Koppanen
My blog: http://valokuva.org
ridera

Re: Can my complex actions be done with IMagick?

Post by ridera »

Here's an example I used to get started with Imagick:
/* This is the IM command version:
-size 900x85 xc:#ffffee -font Bookman-DemiItalic -pointsize 30 -draw "text 10,60 'Image created and saved: 9 Aug 2007 02:36:38 PM'" -channel RGBA -gaussian 0x6 -fill darkred -stroke magenta -draw "text 5,55 'Image created and saved: 9 Aug 2007 02:36:38 PM'"
*/

Then I just took each IM command and used the Imagick equivalent. Some of the parameters are slightly different.

Code: Select all

       $obj2= 	new Imagick();						    //Object
       $draw=	new ImagickDraw();					//Drawing objects
       $color=  new ImagickPixel();					  //Pixels color objects

	$text= 'Image created and saved: ' . date('j M Y h:i A');
	$width= 		940;
	$height= 		85;
	$font_size= 	32;
	$left_margin=	30;
	$top_margin=	55;																//Text and shadow location
	$label_img= './test_label.jpg';

	$color->setColor('skyblue');
	$obj2->newImage($width, $height, $color);	

//Create the label image
	$draw->setFont("Bookman-DemiItalic");	    //Set the font
	$draw->setFontSize($font_size);		        //Set the size

	$color->setColor("black");
	$draw->setFillColor($color);

	$obj2->annotateImage($draw, $left_margin+5, $top_margin+5, 0, $text);		//Add the text shadow

	$obj2->gaussianBlurImage(0, 6); 	//Blur it

	$color->setColor("darkred");										//Text color
	$draw->setFillColor($color);

	$color->setColor('magenta');		 								//Stroke color
	$draw->setStrokeColor($color);
	$draw->annotation($left_margin, $top_margin, $text);				            //Add pretty text

	$obj2->drawImage($draw);									//Add the text layer

/********* 3d Frame it ********************************/
/*
 * The IM command:  -mattecolor Blue -frame 10x10+0+6
*/
 	$color->setColor('blue');

 	$obj2->frameImage($color, 14, 14, 0, 8);

	$obj2->SetImageFormat('jpeg');

	$obj2->writeImage($label_img);

	echo "<img alt=\"image missing\" src=\"./$label_img\">\n\n";
Post Reply