Get the App
SLTechnology News&Howtos  ›  Development  › 

How php uses GD to create thumbnails that maintain aspect ratio

Shulou Source: shulou.com Published: 2022-06-03 19:44:25 09月30日 Update

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

Tags: Articles high ratio value interest at the same time more friends knowledge editing industry information information channels channels reference learning help support Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Linux Huawei macOS Shulou Technology