note 39283 deleted from function.imagerotate by aidan

From: Date: Mon, 04 Oct 2004 07:05:48 +0000
Subject: note 39283 deleted from function.imagerotate by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-77886@lists.php.net to get a copy of this message
Note Submitter: gzin at fr dot fm ---- 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; }

« previous php.notes (#77886) next »