Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How php uses GD to create thumbnails that maintain aspect ratio

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how php uses GD to create thumbnails to maintain aspect ratio, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.

The details are as follows:

/ * 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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report