- How to crop this image?
- http://farm8.staticflickr.com/7164/6671913371_89fbd71a2e_z.jpg
- function thumbanail_for_image($Id, $newfilename, $size=NULL) {
- $file_extension = substr($newfilename, strrpos($newfilename, '.') + 1);
- $arr = explode('.', $newfilename);
- $thumb1 = LOCAL_FOLDER . $arr[0] . "_" . $Id . "." . $file_extension;
- $thumb2 = LOCAL_FOLDER . $arr[0] . "_" . $Id . "b" . "." . $file_extension;
- $old = LOCAL_FOLDER . $newfilename;
- $newfilename = LOCAL_FOLDER . $newfilename;
- $srcImage = "";
- $sizee = getimagesize($newfilename);
- switch ($sizee['mime']) {
- case "image/jpeg" :
- $srcImage = imagecreatefromjpeg($old);
- break;
- case "image/png":
- $srcImage = imagecreatefrompng($old);
- break;
- case "image/gif":
- $srcImage = imagecreatefromgif($old);
- break;
- }
- $srcwidth = $sizee[0];
- $srcheight = $sizee[1];
- if ($srcwidth > $srcheight || $srcwidth < $srcheight) {
- $destwidth1 = 65;
- $rat = $destwidth1 / $srcwidth;
- $destheight1 = (int) ($srcheight * $rat);
- }
- elseif ($srcwidth == $srcheight) {
- $destwidth1 = 65;
- $destheight1 = 65;
- }
- if ($srcwidth > $srcheight || $srcwidth < $srcheight) {
- $destwidth2 = 300;
- $rat = $destwidth2 / $srcwidth;
- $destheight2 = (int) ($srcheight * $rat);
- }
- elseif ($srcwidth == $srcheight) {
- $destwidth2 = 300;
- $destheight2 = 300;
- }
- $destImage1 = imagecreatetruecolor($destwidth1, $destheight1);
- $destImage2 = imagecreatetruecolor($destwidth2, $destheight2);
- imagecopyresampled($destImage1, $srcImage, 0, 0, 0, 0, $destwidth1, $destheight1, $srcwidth, $srcheight);
- imagecopyresampled($destImage2, $srcImage, 0, 0, 0, 0, $destwidth2, $destheight2, $srcwidth, $srcheight);
- if ($sizee['mime'] == "image/jpeg") {
- imagejpeg($destImage1, $thumb1, 80);
- imagejpeg($destImage2, $thumb2, 80);
- } elseif ($sizee['mime'] == "image/png") {
- imagepng($destImage1, $thumb1, 80);
- imagepng($destImage2, $thumb2, 80);
- } elseif ($sizee['mime'] == "image/gif") {
- imagegif($destImage1, $thumb1, 80);
- imagegif($destImage2, $thumb2, 80);
- }
- imagedestroy($destImage1);
- imagedestroy($destImage2);
- chmod($destImage1, 0777);
- chmod($destImage2, 0777);
- return $destImage1;
- }
- [type] =>image/jpeg
- [mime] => image/png