AI智能
改变未来

php 实现图片的等比例缩放

新建index.php,然后指定文件图片名称

<?php
//图片文件名$filename = \"images/51iVPV9tuL._AC_-1-450x450.jpg\";$type = array(\'jpg\',\'jpeg\',\'png\',\'gif\',\'bmp\');$imgType  = explode(\'.\', $filename);$per = 0.8;list($width, $height) = getimagesize($filename);$n_w = $width * $per;$n_h = $height * $per;$newImg = imagecreatetruecolor($n_w, $n_h);$img = imagecreatefromjpeg($filename);$imgName = strtotime(date(\'YmdHis\'));//拷贝部分图像并调整imagecopyresized($newImg, $img, 0, 0, 0, 0, $n_w, $n_h, $width, $height);foreach ($imgType as $item) {if ( in_array($item, $type) ) {//图像输出新图片、另存为imagejpeg($newImg, $imgName .\'.\'. $item);}}imagedestroy($newImg);imagedestroy($img);
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » php 实现图片的等比例缩放