使用PHP调整图像大小
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用PHP调整图像大小相关的知识,希望对你有一定的参考价值。
To use the resize function you must pass in the forced width, forced height, source image, and destination image. The function then uses the GD2 library functions to read the source image's size. It will then calculate the new image's size based off of the forced width and height. This function will maintain the original image's aspect ratio so your image won't look distorted. It won't change the source image at all but when the function is done running you will end up with the destination image which is resized to the dimensions you passed into the function. As far as I know, this function requires the GD2 library although you might be able to get it to work with the GD1 library. The GD library extension must be enabled in php before you can use GD2 functions so keep that in mind as well. You can use the PHP function phpinfo() to see if GD2 is enabled or to see what version of the GD library your server is using.
<?php function resampimagejpg( $forcedwidth, $forcedheight, $sourcefile, $destfile ) { $fw = $forcedwidth; $fh = $forcedheight; if( $is[0] >= $is[1] ) { $orientation = 0; } else { $orientation = 1; $fw = $forcedheight; $fh = $forcedwidth; } if ( $is[0] > $fw || $is[1] > $fh ) { if( ( $is[0] - $fw ) >= ( $is[1] - $fh ) ) { $iw = $fw; $ih = ( $fw / $is[0] ) * $is[1]; } else { $ih = $fh; $iw = ( $ih / $is[1] ) * $is[0]; } $t = 1; } else { $iw = $is[0]; $ih = $is[1]; $t = 2; } if ( $t == 1 ) { { } } else if ( $t == 2 ) { } } ?>
以上是关于使用PHP调整图像大小的主要内容,如果未能解决你的问题,请参考以下文章