public function createThumb($source, $dest, $thumb_size) { $image_properties = getimagesize($source); Header("Content-type: image/jpeg"); $width = $size[0]; $height = $size[1]; if ($width > $height) { $x = ceil(($width - $height) / 2); $width = $height; } elseif ($height > $width) { $y = ceil(($height - $width) / 2); $height = $width; } $new_im = ImageCreatetruecolor($thumb_size, $thumb_size); $im = imagecreatefromjpeg($source); imagecopyresampled($new_im, $im, 0, 0, $x, $y, $thumb_size, $thumb_size, $width, $height); imagejpeg($new_im, $dest, 100); }
function ResizeWidthHeight($picture, $smallfile, $rewidth, $reheight) { $picsize = getimagesize($picture); if ($picsize[2] == 1) { //@header("Content-Type: imgage/gif"); $dstimg = ImageCreatetruecolor($rewidth, $reheight); $srcimg = @ImageCreateFromGIF($picture); ImageCopyResized($dstimg, $srcimg, 0, 0, 0, 0, $rewidth, $reheight, ImageSX($srcimg), ImageSY($srcimg)); Imagegif($dstimg, $smallfile, 100); } elseif ($picsize[2] == 2) { //@header("Content-Type: images/jpeg"); $dstimg = ImageCreatetruecolor($rewidth, $reheight); $srcimg = ImageCreateFromJPEG($picture); imagecopyresampled($dstimg, $srcimg, 0, 0, 0, 0, $rewidth, $reheight, ImageSX($srcimg), ImageSY($srcimg)); Imagejpeg($dstimg, $smallfile, 100); } elseif ($picsize[2] == 3) { //@header("Content-Type: images/png"); $srcimg = ImageCreateFromPNG($picture); $dstimg = imagecreate($rewidth, $reheight); $black = imagecolorallocate($dstimg, 0x0, 0x0, 0x0); $white = imagecolorallocate($dstimg, 0xff, 0xff, 0xff); $magenta = imagecolorallocate($dstimg, 0xff, 0x0, 0xff); imagecolortransparent($dstimg, $black); imagecopyresampled($dstimg, $srcimg, 0, 0, 0, 0, $rewidth, $reheight, ImageSX($srcimg), ImageSY($srcimg)); Imagepng($dstimg, $smallfile, 0); } @ImageDestroy($dstimg); @ImageDestroy($srcimg); }
function create_image() { // *** Generate a passcode using md5 // (it will be all lowercase hex letters and numbers *** $md5 = md5(rand(0, 9999)); $pass = substr($md5, 10, 5); // *** Set the session cookie so we know what the passcode is *** $_SESSION["pass"] = $pass; // *** Create the image resource *** $image = ImageCreatetruecolor(100, 20); // *** We are making two colors, white and black *** $clr_white = ImageColorAllocate($image, 255, 255, 255); $clr_black = ImageColorAllocate($image, 0, 0, 0); // *** Make the background black *** imagefill($image, 0, 0, $clr_black); // *** Set the image height and width *** imagefontheight(15); imagefontwidth(15); // *** Add the passcode in white to the image *** imagestring($image, 5, 30, 3, $pass, $clr_white); // *** Throw in some lines to trick those cheeky bots! *** imageline($image, 5, 1, 50, 20, $clr_white); imageline($image, 60, 1, 96, 20, $clr_white); // *** Return the newly created image in jpeg format *** return imagejpeg($image); // *** Just in case... *** imagedestroy($image); }
private static function _transform($fileName, $toWidth, $toHeight, $typeTransform) { //funkcja zwraca uchwyt do zasobu //zasob jest przeskalowanym odpowiednio obrazkiem $inImage = ImageCreateFromJPEG($fileName); $imgWidth = ImageSX($inImage); $imgHeight = ImageSY($inImage); $size = ImageTransform::_compute_size($imgWidth, $imgHeight, $toWidth, $toHeight, $typeTransform); $outImage = ImageCreatetruecolor($size['width'], $size['height']); imagecopyresampled($outImage, $inImage, 0, 0, 0, 0, $size['width'], $size['height'], $imgWidth, $imgHeight); return $outImage; }
function createThumb($source, $dest) { $thumb_size = 100; $size = getimagesize($source); $width = $size[0]; $height = $size[1]; if ($width > $height) { $x = ceil(($width - $height) / 2); $width = $height; } elseif ($height > $width) { $y = ceil(($height - $width) / 2); $height = $width; } $new_im = ImageCreatetruecolor($thumb_size, $thumb_size); $im = imagecreatefromjpeg($source); imagecopyresampled($new_im, $im, 0, 0, $x, $y, $thumb_size, $thumb_size, $width, $height); imagejpeg($new_im, $dest, 100); }
switch ($ort) { case 6: // 90 rotate right $degrees = 270; break; case 8: // 90 rotate left $degrees = 90; break; } if ($degrees != 0) { $target = imagerotate($target, $degrees, 0); } } } $target = ImageCreatetruecolor($_GET['size'], $_GET['size']); if (preg_match("/.jpg\$/i", $_GET['filename'])) { $source = ImageCreateFromJPEG($_GET['filename']); } if (preg_match("/.gif\$/i", $_GET['filename'])) { $source = ImageCreateFromGIF($_GET['filename']); } if (preg_match("/.png\$/i", $_GET['filename'])) { $source = ImageCreateFromPNG($_GET['filename']); } imagecopyresampled($target, $source, 0, 0, $xoord, $yoord, $_GET['size'], $_GET['size'], $width, $height); imagedestroy($source); //if (preg_match("/.jpg$/i", $_GET['filename'])) ImageJPEG($target,null,90); //if (preg_match("/.gif$/i", $_GET['filename'])) ImageGIF($target,null,90); //if (preg_match("/.png$/i", $_GET['filename'])) ImageJPEG($target,null,90); // Using ImageJPEG on purpose ob_start();
$new_H = ImageSY($src_img); } elseif (ImageSX($src_img) > ImageSY($src_img)) { $new_H = ImageSY($src_img) * ($new_W / ImageSX($src_img)); if ($new_H > $hh) { $new_H = $hh; $new_W = ImageSX($src_img) * ($new_H / ImageSY($src_img)); } } else { $new_W = ImageSX($src_img) * ($new_H / ImageSY($src_img)); if ($new_W > $ww) { $new_W = $ww; $new_H = ImageSY($src_img) * ($new_W / ImageSX($src_img)); } } //$dst_img = ImageCreate($new_W, $new_H);//(GD 版本早於 2.0.1 者,請用此法) $dst_img = ImageCreatetruecolor($new_W, $new_H); //(GD 版本在 2.0.1 以後者,請用此法) ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $new_W, $new_H, ImageSX($src_img), ImageSY($src_img)); if (strtolower(substr($_REQUEST["photo"], -3)) == "gif") { ImageGIF($dst_img); //輸出圖檔 } else { if (strtolower(substr($_REQUEST["photo"], -3)) == "png") { ImagePNG($dst_img); //輸出圖檔 } else { if (strtolower(substr($_REQUEST["photo"], -3)) == "jpg" || strtolower(substr($_REQUEST["photo"], -4)) == "jpeg") { ImageJPEG($dst_img); //輸出圖檔 } }
/** * Generate a random string, and create a CAPTCHA image out of it */ function create_image() { // generate pronouncable pass $pass = genPassword(5, 6); $font = './captcha.ttf'; $maxsize = 50; $sizeVar = 25; $rotate = 20; $bgcol = 50; // + 50 $bgtextcol = 80; // + 50 $textcol = 205; // + 50 // remember the pass $_SESSION["captcha"] = $pass; // calculate dimentions required for pass $box = @imageTTFBbox($maxsize, 0, $font, $pass); $minwidth = abs($box[4] - $box[0]); $minheight = abs($box[5] - $box[1]); // allow spacing for rotating letters $width = $minwidth + 100; $height = $minheight + rand(5, 15); // give some air for the letters to breathe // create initial image $image = ImageCreatetruecolor($width, $height); if (function_exists('imageantialias')) { imageantialias($image, true); } // define background color - never the same, close to black $clr_black = ImageColorAllocate($image, rand($bgcol, $bgcol + 30), rand($bgcol, $bgcol + 30), rand($bgcol, $bgcol + 30)); imagefill($image, 0, 0, $clr_black); // calculate starting positions for letters $x = rand(10, 25); //($width / 2) - ($minwidth / 2); $xinit = $x; $y = $minheight - abs($box[1]) + ($height - $minheight) / 2; // fill the background with big letters, colored a bit lightly, to vary the bg. $bgx = $x / 2; $size = rand($maxsize - 10, $maxsize); for ($i = 0; $i < strlen($pass); $i++) { // modify color a bit $clr_white = ImageColorAllocate($image, rand($bgtextcol, $bgtextcol + 50), rand($bgtextcol, $bgtextcol + 50), rand($bgtextcol, $bgtextcol + 50)); $angle = rand(0 - $rotate, $rotate); $letter = substr($pass, $i, 1); imagettftext($image, $size * 2, $angle, $bgx, $y, $clr_white, $font, $letter); list($x1, $a, $a, $a, $x2) = @imageTTFBbox($size, $angle, $font, $letter); $bgx += abs($x2 - $x1); } // for each letter, decide a color, decide a rotation, put it on the image, // and figure out width to place next letter correctly for ($i = 0; $i < strlen($pass); $i++) { // modify color a bit $clr_white = ImageColorAllocate($image, rand($textcol, $textcol + 50), rand($textcol, $textcol + 50), rand($textcol, $textcol + 50)); $angle = rand(0 - $rotate, $rotate); $letter = substr($pass, $i, 1); $size = rand($maxsize - $sizeVar, $maxsize); $tempbox = @imageTTFBbox($size, $angle, $font, $letter); $y = abs($tempbox[5] - $tempbox[1]) + ($height - abs($tempbox[5] - $tempbox[1])) / 2; imagettftext($image, $size, $angle, $x, $y, $clr_white, $font, $letter); $x += abs($tempbox[4] - $tempbox[0]); } // figure out final width (same space at the end as there was at the beginning) $width = $xinit + $x; // throw in some lines $clr_white = ImageColorAllocate($image, rand(160, 200), rand(160, 200), rand(160, 200)); imagelinethick($image, rand(0, 10), rand(0, $height / 2), rand($width - 10, $width), rand($height / 2, $height), $clr_white, rand(1, 2)); $clr_white = ImageColorAllocate($image, rand(160, 200), rand(160, 200), rand(160, 200)); imagelinethick($image, rand($width / 2 - 10, $width / 2), rand($height / 2, $height), rand($width / 2 + 10, $width), rand(0, $height / 2), $clr_white, rand(1, 2)); // generate final image by cropping initial image to the proper width, // which we didn't know till now. $finalimage = ImageCreatetruecolor($width, $height); if (function_exists('imageantialias')) { imageantialias($finalimage, true); } imagecopy($finalimage, $image, 0, 0, 0, 0, $width, $height); // clear some memory imagedestroy($image); // dump image imagepng($finalimage); // clear some more memory imagedestroy($finalimage); }
if ($width > $height) { $x = ceil(($width - $height) / 2); $width = $height; } elseif ($height > $width) { $y = ceil(($height - $width) / 2); $height = $width; } $new_im = ImageCreatetruecolor($thumb_size, $thumb_size); $im = imagecreatefromgif($source); imagecopyresampled($new_im, $im, 0, 0, $x, $y, $thumb_size, $thumb_size, $width, $height); imagegif($new_im, $dest, 100); } else { if ($image_properties['mime'] == "image/png") { Header("Content-type: image/png"); $size = getimagesize($source); $width = $size[0]; $height = $size[1]; if ($width > $height) { $x = ceil(($width - $height) / 2); $width = $height; } elseif ($height > $width) { $y = ceil(($height - $width) / 2); $height = $width; } $new_im = ImageCreatetruecolor($thumb_size, $thumb_size); $im = imagecreatefrompng($source); imagecopyresampled($new_im, $im, 0, 0, $x, $y, $thumb_size, $thumb_size, $width, $height); imagepng($new_im, $dest, 100); } } }
function create_thumb($src_file, $thumb_file) { $t_width = $this->thumb_width; $t_height = $this->thumb_height; if (!file_exists($src_file)) { return false; } $src_info = getImageSize($src_file); //如果来源图像小于或等于缩略图则拷贝源图像作为缩略图 if ($src_info[0] <= $t_width && $src_info[1] <= $t_height) { if (!copy($src_file, $thumb_file)) { return false; } return true; } //按比例计算缩略图大小 if ($src_info[0] - $t_width > $src_info[1] - $t_height) { $t_height = $t_width / $src_info[0] * $src_info[1]; } else { $t_width = $t_height / $src_info[1] * $src_info[0]; } //取得文件扩展名 $fileext = $this->fileext($src_file); switch ($fileext) { case 'jpg': $src_img = imagecreatefromjpeg($src_file); break; case 'png': $src_img = imagecreatefrompng($src_file); break; case 'gif': $src_img = imagecreatefromgif($src_file); break; } //创建一个真彩色的缩略图像 $thumb_img = ImageCreatetruecolor($this->thumb_width, $this->thumb_height); $clr = imagecolorallocate($thumb_img, 255, 255, 255); imagefilledrectangle($thumb_img, 0, 0, $this->thumb_width, $this->thumb_height, $clr); //ImageCopyResampled函数拷贝的图像平滑度较好,优先考虑 if (function_exists('imagecopyresampled')) { ImageCopyResampled($thumb_img, $src_img, ($this->thumb_width - $t_width) / 2, ($this->thumb_height - $t_height) / 2, 0, 0, $t_width, $t_height, $src_info[0], $src_info[1]); } else { ImageCopyResized($thumb_img, $src_img, 0, 0, 0, 0, $t_width, $t_height, $src_info[0], $src_info[1]); } //生成缩略图 switch ($fileext) { case 'jpg': imagejpeg($thumb_img, $thumb_file, 100); break; case 'gif': imagegif($thumb_img, $thumb_file); break; case 'png': imagepng($thumb_img, $thumb_file); break; } //销毁临时图像 ImageDestroy($src_img); ImageDestroy($thumb_img); return true; }
<?php ////////////////////////////// // The Hosting Tool // Captcha Image // By Reworked Scripts (Original Script by http://thehostingtool.com) // Released under the GNU-GPL ////////////////////////////// session_start(); header("Content-Type: image/jpeg"); $md5 = md5(rand(0, 9999)); $pass = substr($md5, 10, 5); $_SESSION["pass"] = $pass; $image = ImageCreatetruecolor(100, 20); $clr_white = ImageColorAllocate($image, 255, 255, 255); $clr_black = ImageColorAllocate($image, 0, 0, 0); imagefill($image, 0, 0, $clr_black); imagefontheight(15); imagefontwidth(15); imagestring($image, 5, 30, 3, $pass, $clr_white); imageline($image, 5, 1, 50, 20, $clr_white); imageline($image, 60, 1, 96, 20, $clr_white); echo imagejpeg($image); imagedestroy($image);
function create_thumb($source, $target_height = 100) { $size = getimagesize($source); $width = $size[0]; $height = $size[1]; $target_width = round($width * ($target_height / $height)); if ($width > $height) { $x = ceil(($width - $height) / 2); $width = $height; } else { if ($height > $width) { $y = ceil(($height - $width) / 2); $height = $width; } } $new_im = ImageCreatetruecolor($target_width, $target_height); @($imgInfo = getimagesize($source)); if ($imgInfo[2] == IMAGETYPE_JPEG) { $im = imagecreatefromjpeg($source); imagecopyresampled($new_im, $im, 0, 0, $x, $y, $target_width, $target_height, $width, $height); imagejpeg($new_im, $dest, 75); // Thumbnail quality (Value from 1 to 100) } else { if ($imgInfo[2] == IMAGETYPE_GIF) { $im = imagecreatefromgif($source); imagecopyresampled($new_im, $im, 0, 0, $x, $y, $target_width, $target_height, $width, $height); imagegif($new_im, $dest); } else { if ($imgInfo[2] == IMAGETYPE_PNG) { $im = imagecreatefrompng($source); imagecopyresampled($new_im, $im, 0, 0, $x, $y, $target_width, $target_height, $width, $height); imagepng($new_im, $dest); } } } }
} else { $pheight = 140; } header("Content-type: image/jpeg"); // We will create an *.jpg $pic = ImageCreateFromJPEG($url) or die("Image not found!"); if ($pic) { if (substr($url, strlen($url) - 5, 1) == "r") { $pic = imagerotate($pic, 270, 0); } $width = imagesx($pic); $height = imagesy($pic); $twidth = 100; if ($pwidth > 0) { $twidth = $pwidth; } $theight = $twidth * $height / $width; // calculate height if ($pheight > 0) { $theight = $pheight; $twidth = $theight * $width / $height; // $theight = $twidth * $height / $width; # calculate height } $thumb = ImageCreatetruecolor($twidth, $theight) or die("Can't create Image!"); ImageCopyResampled($thumb, $pic, 0, 0, 0, 0, $twidth, $theight, $width, $height); // resize image into thumb ImageCopyResampled ImageCopyResized // ImageJPEG($thumb,"",75); # Thumbnail as JPEG // imagegammacorrect ($thumb, 1.0, 1.4 ) ; ImageJPEG($thumb, null, 95); // Thumbnail as JPEG }
switch ($ort) { case 6: // 90 rotate right $degrees = 270; break; case 8: // 90 rotate left $degrees = 90; break; } if ($degrees != 0) { $target = imagerotate($target, $degrees, 0); } } } $target = ImageCreatetruecolor($res_width, $res_height); if (preg_match("/.jpg\$/i", $_GET['filename'])) { $source = ImageCreateFromJPEG($_GET['filename']); } if (preg_match("/.gif\$/i", $_GET['filename'])) { $source = ImageCreateFromGIF($_GET['filename']); } if (preg_match("/.png\$/i", $_GET['filename'])) { $source = ImageCreateFromPNG($_GET['filename']); } imagecopyresampled($target, $source, 0, 0, $xoord, $yoord, $res_width, $res_height, $width, $height); imagedestroy($source); if ($cache['exist'] == false) { if (preg_match("/.jpg\$/i", $_GET['filename'])) { ImageJPEG($target, null, 90); ImageJPEG($target, $cache['file'], 90);
function _generateImage($type = null, $source = null, $dx = null, $dy = null, $x = null, $y = null, $x_mid = null, $y_mid = null, $new_width = null, $new_height = null, $original_thumb_size_x = null, $original_thumb_size_y = null, $thumb_size_x = null, $thumb_size_y = null, $height = null, $width = null, $letterbox = null, $crop = null, $sharpen = null, $force_letterbox_color = null) { switch ($type) { case 'jpg': case 'jpeg': $im = imagecreatefromjpeg($source); break; case 'png': $im = imagecreatefrompng($source); break; case 'gif': $im = imagecreatefromgif($source); break; default: case null: return false; break; } // CREATE THE NEW IMAGE if (!empty($letterbox)) { // if letterbox, use the originally passed dimensions (keeping the final image size to whatever was requested, fitting the other image inside this box) $new_im = ImageCreatetruecolor($original_thumb_size_x, $original_thumb_size_y); // We want to now set the destination coordinates so we center the image (take overal "box" size and divide in half and subtract by final resized image size divided in half) $dx = ceil($original_thumb_size_x / 2 - $thumb_size_x / 2); $dy = ceil($original_thumb_size_y / 2 - $thumb_size_y / 2); } else { // otherwise, use adjusted resize dimensions $new_im = ImageCreatetruecolor($thumb_size_x, $thumb_size_y); } // If we're cropping, we need to use a different calculated width and height if ($crop === true) { $cropped_im = imagecreatetruecolor(round($new_width), round($new_height)); } if ($type == 'png' || $type == 'gif') { $trnprt_indx = imagecolortransparent($im); // If we have a specific transparent color that was saved with the image if ($trnprt_indx >= 0) { // Get the original image's transparent color's RGB values $trnprt_color = imagecolorsforindex($im, $trnprt_indx); // Allocate the same color in the new image resource $trnprt_indx = imagecolorallocate($new_im, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']); // Completely fill the background of the new image with allocated color. imagefill($new_im, 0, 0, $trnprt_indx); // Set the background color for new image to transparent imagecolortransparent($new_im, $trnprt_indx); if (isset($cropped_im)) { imagefill($cropped_im, 0, 0, $trnprt_indx); imagecolortransparent($cropped_im, $trnprt_indx); } // do the same for the image if cropped } elseif ($type == 'png') { // ...a png may, instead, have an alpha channel that determines its translucency... // Fill the (currently empty) new cropped image with a transparent background if (isset($cropped_im)) { $transparent_index = imagecolortransparent($cropped_im); // allocate //imagepalettecopy($im, $cropped_im); // Don't need to copy the pallette... imagefill($cropped_im, 0, 0, $transparent_index); //imagecolortransparent($cropped_im, $transparent_index); // we need this and the next line even?? for all the trouble i went through, i'm leaving it in case it needs to be turned back on. //imagetruecolortopalette($cropped_im, true, 256); } // Fill the new image with a transparent background imagealphablending($new_im, false); // Create/allocate a new transparent color for image $trnprt_indx = imagecolorallocatealpha($new_im, 0, 0, 0, 127); // $trnprt_indx = imagecolortransparent($new_im, imagecolorallocatealpha($new_im, 0, 0, 0, 127)); // seems to be no difference, but why call an extra function? imagefill($new_im, 0, 0, $trnprt_indx); // Completely fill the background of the new image with allocated color. imagesavealpha($new_im, true); // Restore transparency blending } } // PNG AND GIF can have transparent letterbox and that area needs to be filled too (it already is though if it's transparent) if (!empty($letterbox)) { $background_color = imagecolorallocate($new_im, 255, 255, 255); // default white if (is_array($letterbox) && count($letterbox) == 3) { $background_color = imagecolorallocate($new_im, $letterbox[0], $letterbox[1], $letterbox[2]); } // Transparent images like png and gif will show the letterbox color in their transparent areas so it will look weird if ($type == 'gif' || $type == 'png') { // But we will give the user a choice, forcing letterbox will effectively "flood" the background with that color. if ($force_letterbox_color === true) { imagealphablending($new_im, true); if (isset($cropped_im)) { imagefill($cropped_im, 0, 0, $background_color); } } else { // If the user doesn't force letterboxing color on gif and png, make it transaprent ($trnprt_indx from above) $background_color = $trnprt_indx; } } imagefill($new_im, 0, 0, $background_color); } // If cropping, we have to set some coordinates if ($crop === true) { imagecopyresampled($cropped_im, $im, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // if letterbox we may have to set some coordinates as well depending on the image dimensions ($dx, $dy) unless its letterbox style if (empty($letterbox)) { imagecopyresampled($new_im, $cropped_im, 0, 0, $x_mid - $thumb_size_x / 2, $y_mid - $thumb_size_y / 2, $thumb_size_x, $thumb_size_y, $thumb_size_x, $thumb_size_y); } else { imagecopyresampled($new_im, $cropped_im, $dx, $dy, $x_mid - $thumb_size_x / 2, $y_mid - $thumb_size_y / 2, $thumb_size_x, $thumb_size_y, $thumb_size_x, $thumb_size_y); } } else { imagecopyresampled($new_im, $im, $dx, $dy, $x, $y, $thumb_size_x, $thumb_size_y, $width, $height); } // SHARPEN (optional) -- can't sharpen transparent/translucent PNG if ($sharpen === true && $type != 'png' && $type != 'gif') { $sharpness = $this->_findSharp($width, $thumb_size_x); $sharpenMatrix = array(array(-1, -2, -1), array(-2, $sharpness + 12, -2), array(-1, -2, -1)); $divisor = $sharpness; $offset = 0; imageconvolution($new_im, $sharpenMatrix, $divisor, $offset); } return $new_im; }
$img = @imagecreatefromgif($imagePath); } } } # If an image was successfully loaded, test the image for size if ($img) { # Get image size and scale ratio $width = imagesx($img); $height = imagesy($img); $scale = min(MAX_WIDTH / $width, MAX_HEIGHT / $height); if (module_imageupload_thumb_square) { if ($width > $height) { $x = ceil(($width - $height) / 2); $width = $height; } $tmp_img = ImageCreatetruecolor(MAX_WIDTH, MAX_HEIGHT); @imagecopyresampled($tmp_img, $img, 0, 0, $x, $y, MAX_WIDTH, MAX_HEIGHT, $width, $height); @imagedestroy($img); $img = $tmp_img; } else { # If the image is larger than the max shrink it if ($scale < 1) { $new_width = floor($scale * $width); $new_height = floor($scale * $height); # Create a new temporary image $tmp_img = imagecreatetruecolor($new_width, $new_height); # Copy and resize old image into new image @imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); @imagedestroy($img); $img = $tmp_img; }
if ($ratio < 1) { $width = $width_orig * $ratio; $height = $height_orig * $ratio; } else { $height = $height_orig; $width = $width_orig; } $new_im = ImageCreatetruecolor($width, $height); $im = imagecreatefromgif($source); imagecopyresampled($new_im, $im, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); imagegif($new_im, null, 100); } else { if ($size['mime'] == "image/png") { Header("Content-type: image/png"); $width_orig = $size[0]; $height_orig = $size[1]; $ratio = $width / $width_orig; if ($ratio < 1) { $width = $width_orig * $ratio; $height = $height_orig * $ratio; } else { $height = $height_orig; $width = $width_orig; } $new_im = ImageCreatetruecolor($width, $height); $im = imagecreatefrompng($source); imagecopyresampled($new_im, $im, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); imagepng($new_im, null, 100); } } }
function square($thumb_size) { self::getSizes(); self::$output_type = strtolower(substr(self::getMime(), strpos(self::getMime(), '/') + 1)); $icfunc = "imagecreatefrom" . self::$output_type; $image = @$icfunc(self::$original); $width = self::getWidth(); $height = self::getHeight(); $x = $y = 0; if ($width > $height) { $x = ceil(($width - $height) / 2); $width = $height; } elseif ($height > $width) { $y = ceil(($height - $width) / 2); $height = $width; } $dest = ImageCreatetruecolor($thumb_size, $thumb_size); imagecopyresampled($dest, $image, 0, 0, $x, $y, $thumb_size, $thumb_size, $width, $height); imagejpeg($dest, self::$thumb, self::$quality); self::destroy(); }