<?
function imgResize($image_name, $new_name, $size_name, $watermark, $image = array()) {
$path = $image['move_cat'].$image_name;
$size = getimagesize($path);
$w = $image[$size_name][0]; $h = $image[$size_name][1];
$misratio = $size[0] / $size[1];
if($w / $h < $misratio) $h = $w * $misratio;
else $w = $h * $misratio;
$ext = substr(strchr($image_name,'.'), 1);
$open = 'imagecreatefrom'.$ext;
$save = 'image'.$ext;
$image_temp = imagecreatetruecolor($w, $h);
imagecopyresampled($image_temp, $open($path), 0, 0, 0, 0, $w, $h, $size[0], $size[1]);
if($watermark){
$wm = imagecreatefromgif($image['water_mark']);
$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);
}
$save($image_temp, (empty($new_name)?$path:$image['move_cat'].$new_name.'.'.$ext));
}
$image['view_size'][0] = 550; //w
$image['view_size'][1] = 350; //h
$image['logo_size'][0] = 170;
$image['logo_size'][1] = 110;
$image['move_cat'] = 'img/';
$image['water_mark'] = 'img/wm.gif';
|