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

How to Efficiently Generate Thumbnails from Uploaded Images in PHP? How to Efficiently Generate Thumbnails from Uploaded Images in PHP?

07 Nov 2024

Creating a Thumbnail from an Uploaded ImageGenerating thumbnails for uploaded images ensures they don't appear distorted while preserving the...

Use the powerful imagick to easily generate combined thumbnails under PHP, imagick thumbnails_PHP tutorial Use the powerful imagick to easily generate combined thumbnails under PHP, imagick thumbnails_PHP tutorial

12 Jul 2016

Use the powerful imagick under PHP to easily generate combined thumbnails and imagick thumbnails. Use the powerful imagick to easily generate composite thumbnails under PHP, imagick thumbnails project: blogtarget: use-imagick-to-composite-images-thumbnail.mddate: 2016-02-19status: publishtags: - p

php resizeimage partial jpg file analysis and solutions for failure to generate thumbnails, _PHP tutorial php resizeimage partial jpg file analysis and solutions for failure to generate thumbnails, _PHP tutorial

12 Jul 2016

Analysis and solutions to the reasons why php resizeimage failed to generate thumbnails for some jpg files. php resizeimage partial jpg file analysis and solutions to the reasons for failure to generate thumbnails. Today, when I encountered GD's resizeimage function to process the thumbnail of a jpg suffix file, it prompted that the image is not

How Do I Link Static Libraries That Depend on Other Static Libraries? How Do I Link Static Libraries That Depend on Other Static Libraries?

13 Dec 2024

Linking Static Libraries to Other Static Libraries: A Comprehensive ApproachStatic libraries provide a convenient mechanism to package reusable...

Is there a PHP open source system like piwigo that supports psd upload and generate thumbnails? Is there a PHP open source system like piwigo that supports psd upload and generate thumbnails?

06 Jul 2016

Is there a PHP open source system like piwigo that supports psd upload and generate thumbnails? After using piwigo to build a picture sharing system, I found two problems: 1. The picture is too long and thumbnails cannot be generated. 2. The psd uploaded by ftp cannot generate thumbnails.

How to implement image thumbnails in php, _PHP tutorial How to implement image thumbnails in php, _PHP tutorial

12 Jul 2016

How to implement image thumbnails in php. How to implement image thumbnails in php. Function: supports jpg, jpeg, gif, png, bmp image formats, supports scaling according to the proportion of the original image, and you can choose whether you need to adjust the image during the image scaling process.

See all articles