我很难理解这个函数和包含的代码的问题。
我可以告诉它的所有密集目的都应该没有问题。
我正在运行 GD 库 2.034,这是我正在执行的代码:
function createthumb($name,$filename,$new_w,$new_h){
$system=explode('.',$name);
if (preg_match('/jpg|jpeg/',$system[1])){
$src_img=imagecreatefromjpeg($name);
}
if (preg_match('/png/',$system[1])){
$src_img=imagecreatefrompng($name);
}
//sizing
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y) {
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y) {
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y) {
$thumb_w=$new_w; $thumb_h=$new_h;
}
//keep colours
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
//rebuild image
if (preg_match("/png/",$system[1])) {
imagepng($dst_img,$filename);
}
else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
然后用这个执行:
$filenameresize = strtolower($_FILES['pic']['name']);
$mkfilename = time() . strrchr($filenameresize, '.');
$newfilename = $imagepath . $mkfilename;
createthumb($newfilename, $imagepath . "/thumbs/tn_" . $mkfilename,100,100);
回响
$新文件名如果它在 createthumb 函数之前回显,则给出它的名称,但如果在之后回显则不产生。
我错过了什么?