用下面的php缩略图函数,对某一些jpg图片无法生成缩略图,而其他却可以,这是为啥?
php缩略图生成函数:<?php/**函数功能:把图像缩小到指定大小,若原图比例与新图不一致,从两边裁剪,图像不变形* parameter:* $src_file:源文件* $dst_file:目标文件* $new_width,$new_height:生成图片的宽和高*/function my_image_resize($src_file, $dst_file , $new_width , $new_height) {$src_img=imagecreatefromjpeg($src_file);$w=imagesx($src_img);//原图宽度$h=imagesy($src_img);$ratio_w=1.0 * $new_width / $w;$ratio_h=1.0 * $new_height / $h;$ratio=1.0;if($ratio_w <=1 && $ratio_h <= 1) { if($ratio_w < $ratio_h) { $ratio = $ratio_h ; // 情况一,宽度的比例比高度方向的小,按照高度的比例标准来裁剪或放大 }else { $ratio = $ratio_w ; }// 定义一个中间的临时图像,该图像的宽高比 正好满足目标要求$inter_w=(int)($new_width / $ratio);$inter_h=(int) ($new_height /$ratio);$x=($w-$inter_w)/2;$y=($h-$inter_h)/2;$inter_img=imagecreatetruecolor($inter_w , $inter_h);imagecopy($inter_img, $src_img, 0,0,$x,$y,$inter_w,$inter_h);// 生成一个以最大边长度为大小的是目标图像$ratio比例的临时图像// 定义一个新的图像$new_img=imagecreatetruecolor($new_width,$new_height);//$new_img=iconv("UTF-8","gb2312", $new_img);imagecopyresampled($new_img,$inter_img,0,0,0,0,$new_width,$new_height,$inter_w,$inter_h);imagejpeg($new_img, $dst_file,100);} }?>重新测试了一下,函数第一步imagecreatefromjpeg($src_file);就无法执行了,奇怪的是,只是一部分图片会这样,其他正常,把照片后缀改为png,函数也相应改变后,就可以了,奇怪。