note 39283 added to function.imagerotate

From: Date: Thu, 22 Jan 2004 21:54:22 +0000
Subject: note 39283 added to function.imagerotate
Groups: php.notes 
Request: Send a blank email to php-notes+get-64047@lists.php.net to get a copy of this message
This is an example inspired from allrite's one that works for me : function rotate_image($src, $out, $target, $quality) { $size = getimagesize($src); $tot_x = $size[0]; $tot_y = $size[1]; $imgtype = $size[2]; switch ($imgtype) { case 1: $tmp = imagecreatefromgif($src); break; case 2: $tmp = imagecreatefromjpeg($src); break; case 3: $tmp = imagecreatefrompng($src); break; } if ($tot_x > $tot_y) { $newd = $tot_x; } else { $newd = $tot_y; } if ( !strcmp($target, "-90") ) { if ( function_exists('imagecreatetruecolor') ) { $out_ = imagecreatetruecolor($tot_y, $tot_x); $dst_img = imagecreatetruecolor($newd,$newd); } else { $out_ = imagecreate($tot_y, $tot_x); $dst_img = imagecreate($newd,$newd); } imagecopy($dst_img, $tmp, 0, 0, 0, 0, $tot_x, $tot_y); $rotation= imagerotate($dst_img, "-90", 0); imagecopy($out_, $rotation, 0, 0, ($tot_x > $tot_y) ? ($tot_x - $tot_y): 0, 0, $tot_y, $tot_x); imagedestroy($dst_img); imagedestroy($rotation); } else if ( !strcmp($target, "90") ) { if ( function_exists('imagecreatetruecolor') ) { $out_ = imagecreatetruecolor($tot_y, $tot_x); $dst_img = imagecreatetruecolor($newd,$newd); } else { $out_ = imagecreate($tot_y, $tot_x); $dst_img = imagecreate($newd,$newd); } imagecopy($dst_img, $tmp, 0, 0, 0, 0, $tot_x, $tot_y); $rotation= imagerotate($dst_img, "90", 0); imagecopy($out_, $rotation, 0, 0, 0, ($tot_y > $tot_x) ? ($tot_y - $tot_x): 0, $tot_y, $tot_x); imagedestroy($dst_img); imagedestroy($rotation); } else { $out_ = imagerotate($tmp, "180", 0); } switch ($imgtype) { case 1: imagegif($out_, $out); break; case 2: imagejpeg($out_, $out, $quality); break; case 3: imagepng($out_, $out); break; } imagedestroy($out_); break; default: return 0; break; } return 1; } ---- Manual Page -- http://www.php.net/manual/en/function.imagerotate.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39283 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39283&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39283&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#64047) next »