function create_tolerance($val_1, $val_2) { header("Content-type: image/jpeg"); $image = imageCreatetruecolor(35, 20); $white = imagecolorallocate($image, 255, 255, 255); imagefill($image, 0, 0, $white); $text_color = imagecolorallocate($image, 0, 0, 0); imagestring($image, 2, 0, 0, $val_1, $text_color); imagestring($image, 2, 0, 9, $val_2, $text_color); imagejpeg($image); //输出图像 imagedestory($image); //销毁图像对像 }
function cropimage($im, $startx, $starty, $sizex, $sizey) { $dst = imageCreatetruecolor($sizex, $sizey); $bgcolor = imagecolorallocate($dst, 255, 255, 255); imagefill($dst, 0, 0, $bgcolor); $realsizex = imagesx($im) - $startx; $realsizey = imagesy($im) - $starty; imageCopy($dst, $im, 0, 0, $startx, $starty, $realsizex, $realsizey); // imagePng($dst,"$outfile.png"); return $dst; }
/** * * 直接改变图片大小 * @param $image * @param $dw * @param $dh * @return boolean */ public static function change_size($image, $dw = 450, $dh = 450, $npath = null) { if (!file_exists($image)) { return false; } if (!$npath) { $npath = $image; } $img = self::create_from_ext($image); //创建一个和图片2一样大小的真彩色画布(ps:只有这样才能保证后面copy图片1的时候不会失真) $nimg = imageCreatetruecolor($dw, $dh); //为真彩色画布创建白色背景,再设置为透明 $color = imagecolorallocate($nimg, 255, 255, 255); imagefill($nimg, 0, 0, $color); imageColorTransparent($nimg, $color); //首先将图片2画布采样copy到真彩色画布中,不会失真 #如果是执行调整尺寸操作则 $width = imagesx($img); $height = imagesy($img); imagecopyresampled($nimg, $img, 0, 0, 0, 0, $dw, $dh, $width, $height); #重采样拷贝部分图像并调整大小 imagejpeg($nimg, $npath, 100); #以jpeg格式将图像输出到浏览器或文件 #取得文件的类型,根据不同的类型建立不同的对象 return true; }