$img = imagecreatefromjpeg("C:\\dd.jpg");
$width = imageSX($img);
$height = imageSY($img);
if (!$width || !$height) {
echo "ERROR:invalid width or height";
exit(0);
}
//创建缩略图
$target_width = 100;
$target_height = 100;
$target_ratio = $target_width / $target_height;
$img_ratio = $width / $height;
if ($target_ratio > $img_ratio) {
$new_height = $target_height;
$new_width = $img_ratio * $target_height;
} else {
$new_height = $target_width / $img_ratio;
$new_width = $target_width;
}
if ($new_height > $target_height) {
$new_height = $target_height;
}
if ($new_width > $target_width) {
$new_width = $target_width;
}
$new_img = ImageCreateTrueColor(100, 100);
if (!@imagefilledrectangle($new_img, 0, 0, $target_width - 1, $target_height - 1, 0)) {
echo "ERROR:Could not fill new image";
exit(0);
}
if (!imagecopyresampled($new_img, $img, ($target_width - $new_width) / 2, ($target_height - $new_height) / 2, 0, 0, $new_width, $new_height, $width, $height)) {
echo "ERROR:Could not resize image";
exit(0);
}
ob_start();
imagejpeg($new_img);
$imagevariable = ob_get_contents();
ob_end_clean();
header("Content-type: image/jpeg");
header("Content-Length: " . strlen($imagevariable));
echo $imagevariable;
分享到:
相关推荐
PHPGD库函数概览 PHP开发的基本工具之一。
库函数生成器方便写代码
此文件为软件按转包,其中包括IAR开发环境、STINK驱动以及烧写软件,还有非常实用的STM8库函数自动生成的软件助手
GD32E232库函数与pack包 GD32E232库函数与pack包 GD32E232库函数与pack包 GD32E232库函数与pack包
本人写的STM8S库函数生成器V2.0,有了它就可以扔掉参考手册开发了。
在网站上GD库通常用来生成缩略图,或者用来给图片添加水印,或者用来生成验证码等。幸运的是,SAE默认是对GD库支持的。 本地开发php默认是不支持GD库的,需要自己开启,开启的方式是:在本地PHP安装目录下找到...
自动的生成库函数,不需要手动查到,只需要选择即可
stm8 库函数查询,查询stm8相关函数使用
STM32库函数代码自动生成,基于V3.5库函数版本,配置简单,方便初学者使用
STM8S中文固件库,库函数生成软件,有了它就可以快速对STM8用库开发
GD32F10X固件库函数使用手册
stm32库函数代码生成器。stm32库函数代码生成器。stm32库函数代码生成器。stm32库函数代码生成器。
STM32库函数生成器v1.2版,配有Netframework安装文件,不用在网上找Netframework安装文件,方便直接安装Netframework文件之后就可以使用库函数生成器了。
使用该库函数代码生成器能够产生常用外设的代码配置
作用:取得图片的大小[即长与宽] 用法:array GetImageSize(string filename, array [imageinfo]); ImageArc 作用:画弧线 用法:int ImageArc(int im, int cx, int cy, int w, int h, int s, int e, int col); ...
此程序是基于GD32F130开发的库函数工程模板程序,供参考学习。
1.库的版本为F1的(Libraries.rar里面就是对应的库)! 2.不能使用的朋友,只需要安装个Microsoft .NET Framework 2.0 Service Pack 2即可!我将下载链接贴出来,需要的朋友可自行去下载! 3.某些杀毒软件可能会把此...
在网站上GD库通常用来生成缩略图或者用来对图片加水印或者对网站数据生成报表。 2、部分GD库函数的介绍 imagecreatetruecolor 新建一个真彩色图像 imagecolorallocate 为一幅图像分配颜色(调色板) ...
利用GD库函数生成图片,并在图片上写指定字符 imagecreatetruecolor 新建一个真彩色图像 imagecolorallocate 为一幅图像分配颜色(调色板) imagestring 绘制字符 imageline 绘制线条 imagesetpixel 打像素点 2....
函数代码点击鼠即可生成,常用外设驱动都有,非常方便