<?php
function imgResize($image_path, $new_image_path, $w, $h, $smart_resize = false, $watermark = false, $watermark_path = "") {
$size = getimagesize($image_path);
$misratio = $size[0] / $size[1];
if($w / $h < $misratio) $h = $w * $misratio;
else $w = $h * $misratio;
$ext = strtolower(substr(strchr($image_path, '.'), 1));
$ext = $ext == 'jpg' ? 'jpeg' : $ext;
$open = 'imagecreatefrom' . $ext;
$save = 'image' . $ext;
$image_temp = imagecreatetruecolor($w, $h);
imagecopyresampled($image_temp, $open($image_path), 0, 0, 0, 0, $w, $h, $size[0], $size[1]);
if($watermark){
$wm = imagecreatefromgif($watermark_path);
$wmw = imagesx($wm); $itw = imagesx($image_temp);
$wmh = imagesy($wm); $ith = imagesy($image_temp);
$rx = ($itw - $wmw);
//$trcolor = imagecolorexact($wm, 255, 255, 255);
//imagecolortransparent($wm, $trcolor);
imagecopymerge($image_temp, $wm, $rx, 0, 0, 0, $wmw, $wmh, 35);
}
return $save($image_temp, (empty($new_image_path) ? $image_path : $new_image_path), 80);
}
?>
|