PHP implements the method of generating thumbnails in the original proportion, PHP generates thumbnails in proportion
This article describes the example of PHP in realizing the method of generating thumbnails in the original proportion. Share it with everyone for your reference, the details are as follows:
<?php
$image = "jiequ.jpg"; // 原图
$imgstream = file_get_contents($image);
$im = imagecreatefromstring($imgstream);
$x = imagesx($im);//获取图片的宽
$y = imagesy($im);//获取图片的高
// 缩略后的大小
$xx = 140;
$yy = 200;
if($x>$y){
//图片宽大于高
$sx = abs(($y-$x)/2);
$sy = 0;
$thumbw = $y;
$thumbh = $y;
} else {
//图片高大于等于宽
$sy = abs(($x-$y)/2.5);
$sx = 0;
$thumbw = $x;
$thumbh = $x;
}
if(function_exists("imagecreatetruecolor")) {
$dim = imagecreatetruecolor($yy, $xx); // 创建目标图gd2
} else {
$dim = imagecreate($yy, $xx); // 创建目标图gd1
}
imageCopyreSampled ($dim,$im,0,0,$sx,$sy,$yy,$xx,$thumbw,$thumbh);
header ("Content-type: image/jpeg");
imagejpeg ($dim, false, 100);
?>
Readers who are interested in more PHP-related content can check out the special topics of this site: "Summary of PHP graphics and image operation skills", "Introduction to PHP basic syntax tutorial" and "Summary of common PHP functions and skills"
I hope this article will be helpful to everyone in PHP programming.
Articles you may be interested in:
- How to use timthumb to generate thumbnails in php
- php upload images to generate thumbnails (GD library)
- PHP A simple method to generate a thumbnail album
- A method for php to dynamically generate thumbnails and output them for display
- Thinkphp method to call the Image class to generate thumbnails
- php can generate thumbnails File upload class example
- php method to automatically generate thumbnails based on url
- php method to automatically generate thumbnails for uploaded images
- php method to automatically generate thumbnails based on url and process high Concurrency issues
- Example of php using GD library to generate thumbnails
- Using gd library to realize php server-side picture cropping and thumbnail generation function sharing
http://www.bkjia.com/PHPjc/1098691.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1098691.htmlTechArticleHow to use PHP to generate thumbnails at the original ratio, generate thumbnails at the php ratio. This article describes how to use PHP to generate thumbnails at the original ratio. Thumbnail method. Share it with everyone for your reference, the details are as follows:...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn