Function: Supports jpg, jpeg, gif, png, bmp image formats, supports scaling according to the proportion of the original image, you can choose whether the image needs to be cropped during the image scaling process, and has added image quality control to achieve reduction. Optimize picture quality. The code of the complete class is as follows:
<span>php </span><span>/*</span><span>* * 功能:php生成缩略图片的类 </span><span>*/</span><span>class</span><span> ResizeImage{ </span><span>public</span><span>$type</span>;<span>//</span><span>图片类型</span><span>public</span><span>$width</span>;<span>//</span><span>实际宽度</span><span>public</span><span>$height</span>;<span>//</span><span>实际高度</span><span>public</span><span>$resize_width</span>;<span>//</span><span>改变后的宽度</span><span>public</span><span>$resize_height</span>;<span>//</span><span>改变后的高度</span><span>public</span><span>$cut</span>;<span>//</span><span>是否裁图</span><span>public</span><span>$srcimg</span>;<span>//</span><span>源图象 </span><span>public</span><span>$dstimg</span>;<span>//</span><span>目标图象地址</span><span>public</span><span>$im</span>;<span>//</span><span>临时创建的图象</span><span>public</span><span>$quality</span>;<span>//</span><span>图片质量</span><span>function</span> resizeimage(<span>$img</span>,<span>$wid</span>,<span>$hei</span>,<span>$c</span>,<span>$dstpath</span>,<span>$quality</span>=100<span>){ </span><span>$this</span>->srcimg=<span>$img</span><span>; </span><span>$this</span>->resize_width=<span>$wid</span><span>; </span><span>$this</span>->resize_height=<span>$hei</span><span>; </span><span>$this</span>->cut=<span>$c</span><span>; </span><span>$this</span>->quality=<span>$quality</span><span>; </span><span>$this</span>->type=<span>strtolower</span>(<span>substr</span>(<span>strrchr</span>(<span>$this</span>->srcimg,'.'),1));<span>//</span><span>图片的类型</span><span>$this</span>->initi_img();<span>//</span><span>初始化图象</span><span>$this</span> -> dst_img(<span>$dstpath</span>);<span>//</span><span>目标图象地址</span> @<span>$this</span>->width=imagesx(<span>$this</span>-><span>im); @</span><span>$this</span>->height=imagesy(<span>$this</span>-><span>im); </span><span>$this</span>->newimg();<span>//</span><span>生成图象</span> @ImageDestroy(<span>$this</span>-><span>im); } </span><span>function</span><span> newimg(){ </span><span>$resize_ratio</span>=(<span>$this</span>->resize_width)/(<span>$this</span>->resize_height);<span>//</span><span>改变后的图象的比例</span> @<span>$ratio</span>=(<span>$this</span>->width)/(<span>$this</span>->height);<span>//</span><span>实际图象的比例</span><span>if</span>((<span>$this</span>->cut)=='1'){<span>//</span><span>裁图</span><span>if</span>(<span>$img_func</span>==='imagepng'&&(<span>str_replace</span>('.','',<span>PHP_VERSION</span>)>=512)){ <span>//</span><span>针对php版本大于5.12参数变化后的处理情况</span><span>$quality</span>=9<span>; } </span><span>if</span>(<span>$ratio</span>>=<span>$resize_ratio</span>){<span>//</span><span>高度优先</span><span>$newimg</span>=imagecreatetruecolor(<span>$this</span>->resize_width,<span>$this</span>-><span>resize_height); imagecopyresampled(</span><span>$newimg</span>,<span>$this</span>->im,0,0,0,0,<span>$this</span>->resize_width,<span>$this</span>->resize_height,((<span>$this</span>->height)*<span>$resize_ratio</span>),<span>$this</span>-><span>height); imagejpeg(</span><span>$newimg</span>,<span>$this</span>->dstimg,<span>$this</span>-><span>quality); } </span><span>if</span>(<span>$ratio</span>$resize_ratio){<span>//</span><span>宽度优先</span><span>$newimg</span>=imagecreatetruecolor(<span>$this</span>->resize_width,<span>$this</span>-><span>resize_height); imagecopyresampled(</span><span>$newimg</span>,<span>$this</span>->im,0,0,0,0,<span>$this</span>->resize_width,<span>$this</span>->resize_height,<span>$this</span>->width,((<span>$this</span>->width)/<span>$resize_ratio</span><span>)); imagejpeg(</span><span>$newimg</span>,<span>$this</span>->dstimg,<span>$this</span>-><span>quality); } }</span><span>else</span>{<span>//</span><span>不裁图</span><span>if</span>(<span>$ratio</span>>=<span>$resize_ratio</span><span>){ </span><span>$newimg</span>=imagecreatetruecolor(<span>$this</span>->resize_width,(<span>$this</span>->resize_width)/<span>$ratio</span><span>); imagecopyresampled(</span><span>$newimg</span>,<span>$this</span>->im,0,0,0,0,<span>$this</span>->resize_width,(<span>$this</span>->resize_width)/<span>$ratio</span>,<span>$this</span>->width,<span>$this</span>-><span>height); imagejpeg(</span><span>$newimg</span>,<span>$this</span>->dstimg,<span>$this</span>-><span>quality); } </span><span>if</span>(<span>$ratio</span>$resize_ratio<span>){ @</span><span>$newimg</span>=imagecreatetruecolor((<span>$this</span>->resize_height)*<span>$ratio</span>,<span>$this</span>-><span>resize_height); @imagecopyresampled(</span><span>$newimg</span>,<span>$this</span>->im,0,0,0,0,(<span>$this</span>->resize_height)*<span>$ratio</span>,<span>$this</span>->resize_height,<span>$this</span>->width,<span>$this</span>-><span>height); @imagejpeg(</span><span>$newimg</span>,<span>$this</span>->dstimg,<span>$this</span>-><span>quality); } } } </span><span>function</span> initi_img(){<span>//</span><span>初始化图象</span><span>if</span>(<span>$this</span>->type=='jpg' || <span>$this</span>->type=='jpeg'<span>){ </span><span>$this</span>->im=imagecreatefromjpeg(<span>$this</span>-><span>srcimg); } </span><span>if</span>(<span>$this</span>->type=='gif'<span>){ </span><span>$this</span>->im=imagecreatefromgif(<span>$this</span>-><span>srcimg); } </span><span>if</span>(<span>$this</span>->type=='png'<span>){ </span><span>$this</span>->im=imagecreatefrompng(<span>$this</span>-><span>srcimg); } </span><span>if</span>(<span>$this</span>->type=='wbm'<span>){ @</span><span>$this</span>->im=imagecreatefromwbmp(<span>$this</span>-><span>srcimg); } </span><span>if</span>(<span>$this</span>->type=='bmp'<span>){ </span><span>$this</span>->im=<span>$this</span>->ImageCreateFromBMP(<span>$this</span>-><span>srcimg); } } </span><span>function</span> dst_img(<span>$dstpath</span>){<span>//</span><span>图象目标地址</span><span>$full_length</span>=<span>strlen</span>(<span>$this</span>-><span>srcimg); </span><span>$type_length</span>=<span>strlen</span>(<span>$this</span>-><span>type); </span><span>$name_length</span>=<span>$full_length</span>-<span>$type_length</span><span>; </span><span>$name</span>=<span>substr</span>(<span>$this</span>->srcimg,0,<span>$name_length</span>-1<span>); </span><span>$this</span>->dstimg=<span>$dstpath</span><span>; </span><span>//</span><span>echo $this->dstimg;</span><span> } </span><span>function</span> ImageCreateFromBMP(<span>$filename</span>){ <span>//</span><span>自定义函数处理bmp图片</span><span>if</span>(!<span>$f1</span>=<span>fopen</span>(<span>$filename</span>,"rb"<span>))returnFALSE; </span><span>$FILE</span>=<span>unpack</span>("vfile_type/Vfile_size/Vreserved/Vbitmap_offset",<span>fread</span>(<span>$f1</span>,14<span>)); </span><span>if</span>(<span>$FILE</span>['file_type']!=19778<span>)returnFALSE; </span><span>$BMP</span>=<span>unpack</span>('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'. '/Vcompression/Vsize_bitmap/Vhoriz_resolution'. '/Vvert_resolution/Vcolors_used/Vcolors_important',<span>fread</span>(<span>$f1</span>,40<span>)); </span><span>$BMP</span>['colors']=<span>pow</span>(2,<span>$BMP</span>['bits_per_pixel'<span>]); </span><span>if</span>(<span>$BMP</span>['size_bitmap']==0)<span>$BMP</span>['size_bitmap']=<span>$FILE</span>['file_size']-<span>$FILE</span>['bitmap_offset'<span>]; </span><span>$BMP</span>['bytes_per_pixel']=<span>$BMP</span>['bits_per_pixel']/8<span>; </span><span>$BMP</span>['bytes_per_pixel2']=<span>ceil</span>(<span>$BMP</span>['bytes_per_pixel'<span>]); </span><span>$BMP</span>['decal']=(<span>$BMP</span>['width']*<span>$BMP</span>['bytes_per_pixel']/4<span>); </span><span>$BMP</span>['decal']-=<span>floor</span>(<span>$BMP</span>['width']*<span>$BMP</span>['bytes_per_pixel']/4<span>); </span><span>$BMP</span>['decal']=4-(4*<span>$BMP</span>['decal'<span>]); </span><span>if</span>(<span>$BMP</span>['decal']==4)<span>$BMP</span>['decal']=0<span>; </span><span>$PALETTE</span>=<span>array</span><span>(); </span><span>if</span>(<span>$BMP</span>['colors']) { <span>$PALETTE</span>=<span>unpack</span>('V'.<span>$BMP</span>['colors'],<span>fread</span>(<span>$f1</span>,<span>$BMP</span>['colors']*4<span>)); } </span><span>$IMG</span>=<span>fread</span>(<span>$f1</span>,<span>$BMP</span>['size_bitmap'<span>]); </span><span>$VIDE</span>=<span>chr</span>(0<span>); </span><span>$res</span>=imagecreatetruecolor(<span>$BMP</span>['width'],<span>$BMP</span>['height'<span>]); </span><span>$P</span>=0<span>; </span><span>$Y</span>=<span>$BMP</span>['height']-1<span>; </span><span>while</span>(<span>$Y</span>>=0<span>) { </span><span>$X</span>=0<span>; </span><span>while</span>(<span>$X</span>$BMP['width'<span>]) { </span><span>if</span>(<span>$BMP</span>['bits_per_pixel']==24<span>) </span><span>$COLOR</span>=<span>unpack</span>("V",<span>substr</span>(<span>$IMG</span>,<span>$P</span>,3).<span>$VIDE</span><span>); </span><span>elseif</span>(<span>$BMP</span>['bits_per_pixel']==16<span>) { </span><span>$COLOR</span>=<span>unpack</span>("n",<span>substr</span>(<span>$IMG</span>,<span>$P</span>,2<span>)); </span><span>$COLOR</span>[1]=<span>$PALETTE</span>[<span>$COLOR</span>[1]+1<span>]; } </span><span>elseif</span>(<span>$BMP</span>['bits_per_pixel']==8<span>) { </span><span>$COLOR</span>=<span>unpack</span>("n",<span>$VIDE</span>.<span>substr</span>(<span>$IMG</span>,<span>$P</span>,1<span>)); </span><span>$COLOR</span>[1]=<span>$PALETTE</span>[<span>$COLOR</span>[1]+1<span>]; } </span><span>elseif</span>(<span>$BMP</span>['bits_per_pixel']==4<span>) { </span><span>$COLOR</span>=<span>unpack</span>("n",<span>$VIDE</span>.<span>substr</span>(<span>$IMG</span>,<span>floor</span>(<span>$P</span>),1<span>)); </span><span>if</span>((<span>$P</span>*2)%2==0)<span>$COLOR</span>[1]=(<span>$COLOR</span>[1]>>4);<span>else</span><span>$COLOR</span>[1]=(<span>$COLOR</span>[1]&0x0F<span>); </span><span>$COLOR</span>[1]=<span>$PALETTE</span>[<span>$COLOR</span>[1]+1<span>]; } </span><span>elseif</span>(<span>$BMP</span>['bits_per_pixel']==1<span>) { </span><span>$COLOR</span>=<span>unpack</span>("n",<span>$VIDE</span>.<span>substr</span>(<span>$IMG</span>,<span>floor</span>(<span>$P</span>),1<span>)); </span><span>if</span>((<span>$P</span>*8)%8==0)<span>$COLOR</span>[1]=<span>$COLOR</span>[1]>>7<span>; </span><span>elseif</span>((<span>$P</span>*8)%8==1)<span>$COLOR</span>[1]=(<span>$COLOR</span>[1]&0x40)>>6<span>; </span><span>elseif</span>((<span>$P</span>*8)%8==2)<span>$COLOR</span>[1]=(<span>$COLOR</span>[1]&0x20)>>5<span>; </span><span>elseif</span>((<span>$P</span>*8)%8==3)<span>$COLOR</span>[1]=(<span>$COLOR</span>[1]&0x10)>>4<span>; </span><span>elseif</span>((<span>$P</span>*8)%8==4)<span>$COLOR</span>[1]=(<span>$COLOR</span>[1]&0x8)>>3<span>; </span><span>elseif</span>((<span>$P</span>*8)%8==5)<span>$COLOR</span>[1]=(<span>$COLOR</span>[1]&0x4)>>2<span>; </span><span>elseif</span>((<span>$P</span>*8)%8==6)<span>$COLOR</span>[1]=(<span>$COLOR</span>[1]&0x2)>>1<span>; </span><span>elseif</span>((<span>$P</span>*8)%8==7)<span>$COLOR</span>[1]=(<span>$COLOR</span>[1]&0x1<span>); </span><span>$COLOR</span>[1]=<span>$PALETTE</span>[<span>$COLOR</span>[1]+1<span>]; } </span><span>else</span><span> returnFALSE; imagesetpixel(</span><span>$res</span>,<span>$X</span>,<span>$Y</span>,<span>$COLOR</span>[1<span>]); </span><span>$X</span>++<span>; </span><span>$P</span>+=<span>$BMP</span>['bytes_per_pixel'<span>]; } </span><span>$Y</span>--<span>; </span><span>$P</span>+=<span>$BMP</span>['decal'<span>]; } </span><span>fclose</span>(<span>$f1</span><span>); </span><span>return</span><span>$res</span><span>; } } </span>?>
The usage method is very simple. The code is as follows:
<span>$resizeimage</span>=<span>new</span> ResizeImage('upload/abc.bmp', '120', '90', '0', 'upload/xabc.bmp');
Related reading:
php generate image thumbnail class code sharing
php method to batch generate image thumbnails
php pictures Thumbnail class phpThumb
php Image thumbnail implementation method
php uploads images to generate thumbnails (GD library)
The above introduces the implementation method of PHP image thumbnails, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

许多用户在选择智能手表的时候都会选择的华为的品牌,其中华为GT3pro和GT4都是非常热门的选择,不少用户都很好奇华为GT3pro和GT4有什么区别,下面就就给大家介绍一下二者。华为GT3pro和GT4有什么区别一、外观GT4:46mm和41mm,材质是玻璃表镜+不锈钢机身+高分纤维后壳。GT3pro:46.6mm和42.9mm,材质是蓝宝石玻璃表镜+钛金属机身/陶瓷机身+陶瓷后壳二、健康GT4:采用最新的华为Truseen5.5+算法,结果会更加的精准。GT3pro:多了ECG心电图和血管及安

为什么截图工具在Windows11上不起作用了解问题的根本原因有助于找到正确的解决方案。以下是截图工具可能无法正常工作的主要原因:对焦助手已打开:这可以防止截图工具打开。应用程序损坏:如果截图工具在启动时崩溃,则可能已损坏。过时的图形驱动程序:不兼容的驱动程序可能会干扰截图工具。来自其他应用程序的干扰:其他正在运行的应用程序可能与截图工具冲突。证书已过期:升级过程中的错误可能会导致此issu简单的解决方案这些适合大多数用户,不需要任何特殊的技术知识。1.更新窗口和Microsoft应用商店应用程

第1部分:初始故障排除步骤检查苹果的系统状态:在深入研究复杂的解决方案之前,让我们从基础知识开始。问题可能不在于您的设备;苹果的服务器可能会关闭。访问Apple的系统状态页面,查看AppStore是否正常工作。如果有问题,您所能做的就是等待Apple修复它。检查您的互联网连接:确保您拥有稳定的互联网连接,因为“无法连接到AppStore”问题有时可归因于连接不良。尝试在Wi-Fi和移动数据之间切换或重置网络设置(“常规”>“重置”>“重置网络设置”>设置)。更新您的iOS版本:

Vue中如何对图片进行压缩和格式转换?在前端开发中,经常会遇到需要对图片进行压缩和格式转换的需求。特别是在移动端的开发中,为了提高页面加载速度和节省用户流量,对图片进行压缩和格式转换是很关键的。而在Vue框架中,我们可以通过一些工具库来实现对图片的压缩和格式转换。使用compressor.js库进行压缩compressor.js是一款用于压缩图片的JavaS

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code<form name="myform"

对图片进行resize、裁剪、旋转、翻转首先我们的原始图片是10张网上下载尺寸不一的图片,如下:操作1:resize将图片resize到相同尺寸(320,240)fromPILimportImageimporttorchvision.transformsastransforms#使用PIL库读入图片并进行resizedefResizeImage():ifnotos.path.exists(rdir):os.makedirs(rdir)foriinrange(10):im=Image.open(d

watch4pro和gt各自具有不用的特点和适用场景,如果注重功能的全面性、高性能和时尚外观,同时愿意承担较高的价格,那么Watch 4 Pro可能更适合。如果对功能要求不高,更注重电池续航和价格的合理性,那么GT系列可能更适合。最终的选择应根据个人需求、预算和喜好来决定,建议在购买前仔细考虑自己的需求,并参考各种产品的评测和比较,以做出更明智的选择。

同事因为this指向的问题卡住的bug,vue2的this指向问题,使用了箭头函数,导致拿不到对应的props。当我给他介绍的时候他竟然不知道,随后也刻意的看了一下前端交流群,至今最起码还有70%以上的前端程序员搞不明白,今天给大家分享一下this指向,如果啥都没学会,请给我一个大嘴巴子。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
