Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function resizeimg($filename, $smallimage, $w, $h)
- {
- $size_img = getimagesize($filename);
- $w = $size_img[0];
- $h = $size_img[1];
- $ratio = $w/$h;
- if (($size_img[0]<$w) && ($size_img[1]<$h)) return true;
- $src_ratio=$size_img[0]/$size_img[1];
- if ($ratio<$src_ratio) $h = $w/$src_ratio;
- else $w = $h*$src_ratio;
- $dest_img = imagecreatetruecolor($w, $h);
- $white = imagecolorallocate($dest_img, 255, 255, 255);
- switch($size_img[2])
- {
- case 1:
- {
- $src_img = imagecreatefromgif($filename);
- imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $w, $h, $size_img[0], $size_img[1]);
- imagegif($dest_img, $smallimage);
- }
- case 2:
- {
- $src_img = imagecreatefromjpeg($filename);
- imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $w, $h, $size_img[0], $size_img[1]);
- imagejpeg($dest_img, $smallimage);
- }
- case 3:
- {
- $src_img = imagecreatefrompng($filename);
- imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $w, $h, $size_img[0], $size_img[1]);
- imagepng($dest_img, $smallimage);
- }
- }
- imagedestroy($dest_img);
- imagedestroy($src_img);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement