Jump to content
Larry Ullman's Book Forums

Rotating Images Making Thumbnails


Recommended Posts

Hi everyone, hope all is well.

 

First, I wanted to say thanks again to Larry for making his books and supporting them with this forum. Second, thanks to all the active forum members and all of their support, while I haven't been posting that much I do find myself coming to the forums quite often to read and learn as much as I can. I have learned leaps and bounds. I also try and help out other forum users when I can.

I was looking at my phpinfo(); function and saw a class that appears to come with the php installation.

It is called IMAGICK. I read on the php.net page about some of the methods that come with this class and started to code a simple image Rotation script and a Thumbnail generation script.

 

My question, is it perfectly safe to use IMAGICK vs. Writing my own scripts to handle rotation and thumbnail generation. Does anyone have any suggestions on my code to make better?

 

Here is a simple sample code that I wrote using some functions on the php.net page

 

http://www.php.net/manual/en/class.imagick.php

 

$image = new Imagick("/home/{$JAEPEE}/public/{$user_folder}/{$main_pic}"); // main image
$thumb = new Imagick("/home/{$JAEPEE}/{$folder}/thumbs/{$thumb}");  // thb
// this code rotates an image ... //
$image->rotateImage(new ImagickPixel(), $degrees); // main 180 flip // 270 rotate left // rotate right //
$thumb->rotateImage(new ImagickPixel(), $degrees); // thb// 180 -> flip//  270 -> rotates left // 90 -> rotates right //

// thumbnail code ...
//$image1->thumbnailImage(150,150,true); // creates thumbnail to size 150
//$image1->cropThumbnailImage(150,150); // crops and keeps aspect ratio

// writes image to folder
$m = $image->writeImage("/home/{$JAEPEE}/public/{$user_folder}/{$main_pic}");
$t = $image1->writeImage("/home/{$JAEPEE}/public/{$user_folder}/thumbs/{$thumb}"); // saves the thumbnail at the given destination
if ($t && $m) {
echo 'Image was rotated';
} else {
echo 'No go on the rotate';
}

 

The rotate feature works pretty darn good, and it's really fast too.

Thanks Everyone

jp

Link to comment
Share on other sites

 Share

×
×
  • Create New...