Home > php教程 > php手册 > php使用GD创建保持宽高比缩略图的方法

php使用GD创建保持宽高比缩略图的方法

WBOY
Release: 2016-06-06 20:04:57
Original
972 people have browsed it

这篇文章主要介绍了php使用GD创建保持宽高比缩略图的方法,涉及php使用GD库操作图片的技巧,需要的朋友可以参考下

本文实例讲述了php使用GD创建保持宽高比缩略图的方法。分享给大家供大家参考。具体如下:

/** * Create a thumbnail image from $inputFileName no taller or wider than * $maxSize. Returns the new image resource or false on error. * Author: mthorn.net */ function thumbnail($inputFileName, $maxSize = 100) { $info = getimagesize($inputFileName); $type = isset($info['type']) ? $info['type'] : $info[2]; // Check support of file type if ( !(imagetypes() & $type) ) { // Server does not support file type return false; } $width = isset($info['width']) ? $info['width'] : $info[0]; $height = isset($info['height']) ? $info['height'] : $info[1]; // Calculate aspect ratio $wRatio = $maxSize / $width; $hRatio = $maxSize / $height; // Using imagecreatefromstring will automatically detect the file type $sourceImage = imagecreatefromstring(file_get_contents($inputFileName)); // Calculate a proportional width and height no larger than the max size. if ( ($width

希望本文所述对大家的php程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template