Home PHP Libraries Other libraries PHP class to generate thumbnails
PHP class to generate thumbnails
<?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


Disclaimer

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

Generate thumbnails PHP code to batch generate thumbnails Generate thumbnails PHP code to batch generate thumbnails

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

PHP image upload class and generate thumbnails PHP image upload class and generate thumbnails

25 Jul 2016

PHP image upload class and generate thumbnails

PHP image file upload class (can automatically generate thumbnails) PHP image file upload class (can automatically generate thumbnails)

25 Jul 2016

PHP image file upload class (can automatically generate thumbnails)

Thinkphp calls the Image class to generate thumbnails, thinkphpimage_PHP tutorial Thinkphp calls the Image class to generate thumbnails, thinkphpimage_PHP tutorial

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

How to generate thumbnails in php How to generate thumbnails in php

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.

PHP uploads images to generate thumbnails PHP uploads images to generate thumbnails

25 Jul 2016

PHP uploads images to generate thumbnails

See all articles