


Sharing code for generating image thumbnails with PHP based on GD2 graphics library
This article mainly introduces sharing code for generating image thumbnails with PHP based on GD2 graphics library. This article directly The implementation code and usage methods are given, friends in need can refer to it
To use PHP to generate image thumbnails, make sure your PHP server has the GD2 graphics library installed. Use a class to generate image thumbnails
1. How to use
?
|
$resizeimage = new resizeimage("Image source file address", "200", "100", "0","Thumbnail address"); // Just use the above sentence to generate a thumbnail. The source file and thumbnail addresses can be the same, 200 and 100 represent the width and height respectively |
2. Thumbnail code
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
//Use the following class to generate image thumbnails,
class resizeimage { //Picture type var $type; //Actual width var $width; //Actual height var $height; //Changed width var $resize_width; //Changed height var $resize_height; //Whether to crop the image var $cut; //Source image var $srcimg; //Target image address var $dstimg; //Temporarily created image var $im;
function resizeimage($img, $wid, $hei,$c,$dstpath) { $this->srcimg = $img; $this->resize_width = $wid; $this->resize_height = $hei; $this->cut = $c; //Type of picture
$this->type = strtolower(substr(strrchr($this->srcimg,"."),1));
//Initialize image $this->initi_img(); //Target image address $this -> dst_img($dstpath); //-- $this->width = imagesx($this->im); $this->height = imagesy($this->im); //Generate image $this->newimg(); ImageDestroy ($this->im); } function newimg() { //The proportion of the changed image $resize_ratio = ($this->resize_width)/($this->resize_height); //Proportion of actual image $ratio = ($this->width)/($this->height); if(($this->cut)=="1") //裁图 { if($ratio>=$resize_ratio) //高度优先 { $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width,$this->resize_height, (($this->height)*$resize_ratio), $this->height); ImageJpeg ($newimg,$this->dstimg); } if($ratio //宽度优先 { $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, (($this->width)/$resize_ratio)); ImageJpeg ($newimg,$this->dstimg); } } else //不裁图 { if($ratio>=$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,($this->resize_width)/$ratio); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, ($this->resize_width)/$ratio, $this->width, $this->height); ImageJpeg ($newimg,$this->dstimg); } if($ratio { $newimg = imagecreatetruecolor(($this->resize_height)*$ratio,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, ($this->resize_height)*$ratio, $this->resize_height, $this->width, $this->height); ImageJpeg ($newimg,$this->dstimg); } } } //初始化图象 function initi_img() { if($this->type=="jpg") { $this->im = imagecreatefromjpeg($this->srcimg); } if($this->type=="gif") { $this->im = imagecreatefromgif($this->srcimg); } if($this->type=="png") { $this->im = imagecreatefrompng($this->srcimg); } } //图象目标地址 function dst_img($dstpath) { $full_length = strlen($this->srcimg);
$type_length = strlen($this->type); $name_length = $full_length-$type_length;
$name = substr($this->srcimg,0,$name_length-1); $this->dstimg = $dstpath;
//echo $this->dstimg; } } |

五大热门Go语言库汇总:开发必备利器,需要具体代码示例Go语言自从诞生以来,受到了广泛的关注和应用。作为一门新兴的高效、简洁的编程语言,Go的快速发展离不开丰富的开源库的支持。本文将介绍五大热门的Go语言库,这些库在Go开发中扮演了至关重要的角色,为开发者提供了强大的功能和便捷的开发体验。同时,为了更好地理解这些库的用途和功能,我们会结合具体的代码示例进行讲

如今全球各个行业内 Python 的使用状况怎么样呢?这个问题就是我写这篇文章的初衷。我找出了22个最常用的 Python 包,希望能给你一些启发。首先我列出了最近一年内 PyPI 上下载量最高的 Python 包。我们来看看这些包的作用,它们的之间的关系,以及为什么会如此流行。1、Urllib38.93亿次下载Urllib3 是 Python 的 HTTP 客户端,它提供了许多 Python 标准库没有的功能。 线程安全 连接池 客户端 SSL/TLS 验证 使用 multipart 编码进行

PHP8.0中的国际化库:UnicodeCLDR和Intl扩展随着全球化的进程,开发跨语言、跨地域的应用程序变得越来越普遍。国际化是实现这一目标的重要组成部分。在PHP8.0中,引入了UnicodeCLDR和Intl扩展,这两个组件都为开发者提供了更好的国际化支持。UnicodeCLDRUnicodeCLDR(CommonLocaleDat

Pillow库是Python中一个非常强大的图像处理库,它基于PythonImagingLibrary(PIL)发展而来,并在其基础上进行了优化和扩展。Pillow库提供了丰富的图像处理功能,可以处理各种类型的图像文件,并进行图像的编辑、合并、滤镜处理等操作。本文将为大家提供一个Pillow库的安装指南,帮助你轻松掌握这个强大的图像处理工具。一、安装P

这款芯片可能会搭载高达80个GPU核心,进而成为M3系列中性能最强大的产品。Max两倍核心数量从M1与M2系列的发展模式来看,苹果的「Ultra」版芯片基本上是「Max」版本的两倍核心数量,这是因为苹果实际上将两颗Max芯片透过内部连接技术结合起来,形成了M1Ultra与M2Ultra。80个GPU核心M3Ultra可能拥有「高达80个图形处理核心」。这一预测基于苹果芯片的发展路径:从基础版到「Pro」版,再到图形核心数量翻倍的「Max」版,以及CPU和GPU核心都翻倍的「Ultra」版。举例来

简介XML(可扩展标记语言)是一种用于存储和传输数据的流行格式。在Java中解析XML是许多应用程序的一个必要任务,从数据交换到文档处理。为了有效地解析XML,开发人员可以使用各种Java库。本文将比较一些最流行的XML解析库,重点关注它们的特性、功能和性能,以帮助开发人员做出明智的选择。DOM(文档对象模型)解析库JavaXMLDOMAPI:由oracle提供的标准DOM实现。它提供了一个对象模型,允许开发人员访问和操作XML文档。DocumentBuilderFactoryfactory=D

amd图形显卡排行1、Radeon需要重新写作的内容是:RX需要重新写作的内容是:6950XT2、Radeon需要重新写作的内容是:RX需要重新写作的内容是:6900XT需要重写的是:3、Radeon需要重新写作的内容是:RX需要重新写作的内容是:6800XT4、Radeon需要重新写作的内容是:RX需要重新写作的内容是:6800需要重写的是:5、Radeon需要重新写作的内容是:RX需要重新写作的内容是:6750XT6、Radeon需要重新写作的内容是:RX需要重新写作的内容是:6700XT7

PyCharm添加库的方法和技巧大揭秘PyCharm是一款功能强大的Python集成开发环境,为Python开发者提供了丰富的功能和工具。在使用PyCharm进行开发的过程中,添加库是一个常见的需求。本文将详细介绍PyCharm添加库的方法和技巧,包括通过PyCharm自带的功能和使用pip工具安装库。一、通过PyCharm自


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

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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