<?php
/**
 * [UQcms System] Copyright uqcms.com
 * QQ: 2200631718
 * Author: gj.name
 * This is NOT a freeware
*/
defined('IN_UQ') or exit('Access Denied'); class images { public static function crop($src_file,$cut_x,$cut_y,$cut_w,$cut_h,$new_save_path = ''){ $img_type = self::image_type($src_file); switch ($img_type) { case 'jpg' : $src_file = ImageCreateFromJPEG($src_file); break; case 'png' : $src_file = ImageCreateFromPNG($src_file); break; case 'gif' : $src_file = ImageCreateFromGIF($src_file); break; } $cut_img = imagecreatetruecolor($cut_w, $cut_h); imagecopy($cut_img, $src_file, 0, 0, $cut_x, $cut_y, $cut_w, $cut_h); if(!empty($new_save_path)){ $pic_data = date("y").'/'.date("md").'/'; $pic_name = rand('10000','99999').(date("dhis",time()).microtime()*1000000).'.'.$img_type; $src_file = $new_save_path.'/'.$pic_data.$pic_name; } self::mk_dirs($src_file); self::dst_output_file($src_file,$cut_img,$src_file); return $src_file; } public static function thumb($src_file,$new_w=0,$new_h=0){ $size = getimagesize($src_file); if($new_w != 0 && $new_h == 0){ $new_h = $size[1]/($size[0]/$new_w); } if($new_h != 0 && $new_w == 0){ $new_w = $size[0]/($size[1]/$new_h); } $img_type = self::image_type($src_file); switch ($img_type) { case 'jpg' : $src_file = ImageCreateFromJPEG($src_file); break; case 'png' : $src_file = ImageCreateFromPNG($src_file); break; case 'gif' : $src_file = ImageCreateFromGIF($src_file); break; } $dst_img = imagecreatetruecolor($new_w, $new_h); imagecopyresampled($dst_img, $src_file, 0, 0, 0, 0, $new_w, $new_h, $size[0], $size[1]); if(!empty($new_save_path)){ $pic_data = date("y").'/'.date("md").'/'; $pic_name = rand('10000','99999').(date("dhis",time()).microtime()*1000000).'.'.$img_type; $src_file = $new_save_path.'/'.$pic_data.$pic_name; } $new_file_url = $src_file.'_'.$new_w.'.'.$img_type; self::mk_dirs($new_file_url); self::dst_output_file($src_file,$dst_img,$new_file_url); return $src_file; } private static function dst_output_file($src_file,$dst_img,$new_file_name){ $img_type = self::image_type($src_file); switch ($img_type) { case 'jpg' : ImageJPEG($dst_img,$new_file_name,80); break; case 'gif' : ImageGIF($dst_img,$new_file_name); break; case 'png' : ImagePNG($dst_img,$new_file_name); break; } @ImageDestroy($src_file); @ImageDestroy($dst_img); } public static function mk_dirs($path,$up_dir = ''){ $adir = explode('/',$path); array_pop($adir); $dirlist = $up_dir; $rootdir = array_shift($adir); if(($rootdir != '.'|| $rootdir != '..')&&!file_exists($rootdir)){ @mkdir($rootdir); } foreach($adir as $key=>$val){ if($val != '.' && $val != '..'){ $dirlist .= "/".$val; $dirpath = $rootdir.$dirlist; if(!file_exists($dirpath)){ @mkdir($dirpath); @chmod($dirpath,0777); } } } } private static function image_type($dst_img){ $img_type_array = array('jpg','png','gif'); $img_type = substr($dst_img,-3); return $img_type; } private static function dst_output_img($dst_img){ header('Content-Type: image/jpeg'); imagejpeg($dst_img); } }