pic_type = "gif"; return true; } case 2 : { $this->pic_type = "jpeg"; return true; } case 3 : { $this->pic_type = "png"; return true; } default : { //$this->warning("Not valid image type!"); return false; } } } function _imagecreatefrom($filename) { $_imagecreatefrom = "imagecreatefrom".$this->pic_type; $image = $_imagecreatefrom($filename); return $image; } function _image(&$image_o, $filename, $quality = 75) { $_image = "image".$this->pic_type; $_image($image_o, $filename, $quality); } function Resize_IMG($filename,$resize_width = 0,$resize_height = 0, $pr = false) { if($resize_width < 1 && $resize_height < 1) return true; list($original_width, $original_height, $type) = getimagesize($filename); if($resize_width>$original_width && $resize_height>$original_height) return true; $this->_setType($type); if($pr) { if($resize_width < 1) $resize_width = $original_width; $height = $original_height*($resize_width/$original_width); $width = $resize_width; if($resize_height > 0) { if($height>$resize_height) { $width = $original_width*($resize_height/$original_height); $height = $resize_height; } } if($width>$original_width) return true; } else { if($resize_width < 1) $resize_width = $original_width; if($resize_height < 1) $resize_height = $original_height; $width = $resize_width; $height = $resize_height; } if($width < 1 || $height < 1) { $width = $original_width; $height = $original_height; } $x = 0; $y = 0; if(!$pr) { if ($original_width >= $width && $original_height >= $height) { if($original_height < $original_width) { $ratio = (double)($original_height / $height); $cpyWidth = $width * $ratio; if ($cpyWidth > $original_width) { $ratio = (double)($original_width / $width); $cpyWidth = $original_width; $cpyHeight = $height * $ratio; //$y = ($original_height - $cpyHeight) / 2; } else { $cpyHeight = $original_height; $x = ($original_width - $cpyWidth) / 2; } } else { $ratio = (double)($original_width / $width); $cpyHeight = $height * $ratio; if ($cpyHeight > $original_height) { $ratio = (double)($original_height / $height); $cpyHeight = $original_height; $cpyWidth = $width * $ratio; $x = ($original_width - $cpyWidth) / 2; } else { $cpyWidth = $original_width; //$y = ($original_height - $cpyHeight) / 2; } } $original_width = $cpyWidth; $original_height = $cpyHeight; } else if($original_width<$width) { $width = $original_width*($height/$original_height); $height = $resize_height; } else { $height = $original_height*($width/$original_width); $width = $resize_width; } } $width = round($width); $height = round($height); $width = round($width); $height = round($height); $width = round($width); $height = round($height); $this->image = imagecreatetruecolor($width, $height); $handle = $this->_imagecreatefrom($filename); imagecopyresampled($this->image, $handle, 0, 0, $x, $y, $width, $height, $original_width, $original_height); imagedestroy($handle); if($width<=120) $quality = 100; else $quality = 75; $this->_image($this->image, $filename, $quality); imagedestroy($this->image); return true; } function forse_resize_image($file, $w, $h, $crop=FALSE) { list($width, $height) = getimagesize($file); $r = $width / $height; if ($crop) { if ($width > $height) { $width = ceil($width-($width*abs($r-$w/$h))); } else { $height = ceil($height-($height*abs($r-$w/$h))); } $newwidth = $w; $newheight = $h; } else { if ($w/$h > $r) { $newwidth = $h*$r; $newheight = $h; } else { $newheight = $w/$r; $newwidth = $w; } } $src = imagecreatefromjpeg($file); $dst = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); return $dst; } function square_resize($max_width, $max_height, $source_file, $dst_dir, $quality = 80){ $imgsize = getimagesize($source_file); $width = $imgsize[0]; $height = $imgsize[1]; $mime = $imgsize['mime']; switch($mime){ case 'image/gif': $image_create = "imagecreatefromgif"; $image = "imagegif"; break; case 'image/png': $image_create = "imagecreatefrompng"; $image = "imagepng"; $quality = 7; break; case 'image/jpeg': $image_create = "imagecreatefromjpeg"; $image = "imagejpeg"; $quality = 80; break; default: return false; break; } $dst_img = imagecreatetruecolor($max_width, $max_height); $src_img = $image_create($source_file); $width_new = $height * $max_width / $max_height; $height_new = $width * $max_height / $max_width; //if the new width is greater than the actual width of the image, then the height is too large and the rest cut off, or vice versa if($width_new > $width){ //cut point by height $h_point = (($height - $height_new) / 2); //copy image imagecopyresampled($dst_img, $src_img, 0, 0, 0, $h_point, $max_width, $max_height, $width, $height_new); }else{ //cut point by width $w_point = (($width - $width_new) / 2); imagecopyresampled($dst_img, $src_img, 0, 0, $w_point, 0, $max_width, $max_height, $width_new, $height); } //$image($dst_img, $dst_dir, $quality); return $dst_img; /*if($dst_img)imagedestroy($dst_img); if($src_img)imagedestroy($src_img);*/ } function set_logo($filename) { list($width, $height, $type) = getimagesize($filename); $this->_setType($type); $_image = "image".$this->pic_type; $_imagecreatefrom = "imagecreatefrom".$this->pic_type; $image = $_imagecreatefrom($filename); $logo_path='images/logo.png'; $logo = imagecreatefrompng($logo_path); list($lwidth, $lheight, $ltype) = getimagesize($logo_path); $src_x = $width - ($lwidth + 5); $src_y = $height - ($lheight + 5); ImageCopy($image,$logo, $src_x,$src_y,0,0,$lwidth,$lheight); $_image($image, $filename); unset($image); unset($logo); } } ?>