php 修改图片大小

<?php
set_time_limit(0);
ini_set("memory_limit","500M");
$dir = dir('./');
while (false!==($e=$dir->read())) {
if (is_dir($e)) {
$dir1 = dir($e);
while (false!==($b=$dir1->read())) {


$file = explode('.', $b);
$ext = end($file);
if ($ext=='jpg'||$ext=='png') {

$arr = getimagesize($e.'/'.$b);
// print_r($arr);die;
if ($arr['mime']=='image/png') {
$src = ImageCreateFromPNG($e.'/'.$b);

}else{
$src = ImageCreateFromJPEG($e.'/'.$b);
}
// $src = ImageCreateFromJPEG($b);
$width = ImageSx($src);
$height = ImageSy($src);
$x = 750;
$y = 750;
$dst = ImageCreateTrueColor($x,$y);
ImageCopyResampled($dst,$src,0,0,0,0,$x,$y,$width,$height);
if ($arr['mime']=='image/png') {
header('Content-Type : image/png');
ImagePNG($dst,$e.'/'.$b);
}
header('Content-Type : image/jpeg');
Imagejpeg($dst,$e.'/'.$b);
}
}
}
}

原文地址:https://www.cnblogs.com/zhaoxiangshang/p/10494959.html