<?php //功能:生成缩略图 class CreatMiniature { //公共变量 var $srcFile = ""; //原图 var $echoType; //输出图片类型,link--不保存为文件;file--保存为文件 var $im = ""; //临时变量 var $srcW = ""; //原图宽 var $srcH = ""; //原图高 //设置变量及初始化 function SetVar($srcFile, $echoType) { if (!file_exists($srcFile)) { echo '源图片文件不存在!'; exit(); } $this->srcFile = $srcFile; $this->echoType = $echoType; $info = ""; $data = GetImageSize($this->srcFile, $info); switch ($data[2]) { case 1: if (!function_exists("imagecreatefromgif")) { echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!返回"; exit(); }
Generate thumbnail function (supports image formats: gif, jpeg, png and bmp)
* @author ruxing.li
* @param string $src Source image path
* @param int $width Thumbnail width (conformal scaling is performed when only the height is specified)
* @param int $width Thumbnail height (conformal scaling is performed when only the width is specified)
* @param string $filename Save path (directly output to the browser if not specified)
* @return bool
All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn
Related Article
29 Jul 2016
Generate thumbnails: Generate thumbnails PHP code for batch generating thumbnails: Disadvantages: Pictures of different lengths and widths will be stretched and deformed, and cannot be intelligently cropped. If you need intelligent cropping, please do your own research. <?php $config = array(); $config['path'] = "./"; $config['t_width'] = 120; $config['t_height'] = 98; $config['ignore'] = array("",".",".."); $config['pre
25 Jul 2016
PHP image upload class and generate thumbnails
25 Jul 2016
PHP image file upload class (can automatically generate thumbnails)
13 Jul 2016
Thinkphp calls the method of Image class to generate thumbnails, thinkphpimage. Thinkphp calls the Image class to generate thumbnails, thinkphpimage This article describes the example of Thinkphp calling the Image class to generate thumbnails. Share it with everyone for your reference. The specific analysis is as follows
19 May 2017
In our PHP website development, we often need to process images. The most common one is to generate thumbnails for uploaded images or images in articles. Here are 10 codes for generating thumbnails using PHP summarized by PHP Chinese website for you. Use and download!
08 Jun 2018
This article mainly introduces the method of generating thumbnails in php. Interested friends can refer to it. I hope it will be helpful to everyone.
Hot Tools
PHP library for dependency injection containers
PHP library for dependency injection containers
A collection of 50 excellent classic PHP algorithms
Classic PHP algorithm, learn excellent ideas and expand your thinking
Small PHP library for optimizing images
Small PHP library for optimizing images