<?php //功能:生成縮略圖 class CreatMiniature { //公共變量 var $srcFile = ""; //原圖 var $echoType; //輸出圖片類型,link--不保存為文件;file--保存為文件 var $im = ""; //臨時變量 var $srcW = ""; //原圖寬 var $srcH = ""; //原圖高 //設(shè)置變量及初始化 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

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

10 Mar 2025
This article explores generating dynamic XML content using PHP and Python. It details methods using string manipulation and XML libraries (DOMDocument/ElementTree), emphasizing best practices for security (input validation, XXE prevention, XSS prote

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

05 Nov 2024
Creating Scaled Thumbnails in PHPThe provided code snippet successfully crops an image within a given dimension. However, for larger images, it...

18 Dec 2024
How to Retrieve YouTube Video Thumbnails using PHP and cURLQuestion:How to retrieve YouTube Video Thumbnails from YouTube API using PHP and cURLQuestion...

30 Jan 2025
How to Dynamically Generate a Class at Runtime?Consider the following scenario: you have a class that represents a set of fields and their...


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
