|
@@ -123,7 +123,44 @@ class ImageCompressService
|
|
|
$image = imagecreatefromjpeg($path);
|
|
$image = imagecreatefromjpeg($path);
|
|
|
break;
|
|
break;
|
|
|
case IMAGETYPE_PNG:
|
|
case IMAGETYPE_PNG:
|
|
|
- $image = imagecreatefrompng($path);
|
|
|
|
|
|
|
+ // PNG特殊处理
|
|
|
|
|
+ outFileLog('开始处理PNG图片: ' . $path, 'upload_img', 'png_process_start');
|
|
|
|
|
+
|
|
|
|
|
+ // 检查文件大小
|
|
|
|
|
+ $fileSize = filesize($path);
|
|
|
|
|
+ outFileLog('PNG文件大小: ' . $fileSize . ' bytes', 'upload_img', 'png_file_size');
|
|
|
|
|
+
|
|
|
|
|
+ // 检查内存限制
|
|
|
|
|
+ $memoryLimit = ini_get('memory_limit');
|
|
|
|
|
+ $currentMemory = memory_get_usage(true);
|
|
|
|
|
+ outFileLog('内存限制: ' . $memoryLimit . ', 当前使用: ' . $currentMemory, 'upload_img', 'memory_info');
|
|
|
|
|
+
|
|
|
|
|
+ // 尝试创建PNG图片资源
|
|
|
|
|
+ $image = @imagecreatefrompng($path);
|
|
|
|
|
+
|
|
|
|
|
+// $image = imagecreatefrompng($path);
|
|
|
|
|
+ if ($image === false) {
|
|
|
|
|
+ // 获取详细错误信息
|
|
|
|
|
+ $error = error_get_last();
|
|
|
|
|
+ outFileLog('PNG创建失败,错误信息: ' . json_encode($error), 'upload_img', 'png_create_error');
|
|
|
|
|
+ // 尝试验证PNG文件头
|
|
|
|
|
+ $handle = fopen($path, 'rb');
|
|
|
|
|
+ $header = fread($handle, 8);
|
|
|
|
|
+ fclose($handle);
|
|
|
|
|
+ $pngSignature = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
|
|
|
|
|
+
|
|
|
|
|
+ if ($header !== $pngSignature) {
|
|
|
|
|
+ throw new Exception('PNG文件头不正确,文件可能损坏');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 尝试使用getimagesize验证
|
|
|
|
|
+ $imageInfo = @getimagesize($path);
|
|
|
|
|
+ if ($imageInfo === false) {
|
|
|
|
|
+ throw new Exception('PNG文件无法被识别,可能已损坏');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ outFileLog('PNG图片信息: ' . json_encode($imageInfo), 'upload_img', 'png_image_info');
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
case IMAGETYPE_GIF:
|
|
case IMAGETYPE_GIF:
|
|
|
$image = imagecreatefromgif($path);
|
|
$image = imagecreatefromgif($path);
|
|
@@ -141,10 +178,11 @@ class ImageCompressService
|
|
|
if (!$image) {
|
|
if (!$image) {
|
|
|
throw new Exception('创建图片资源失败,可能是内存不足或文件损坏');
|
|
throw new Exception('创建图片资源失败,可能是内存不足或文件损坏');
|
|
|
}
|
|
}
|
|
|
- outFileLog($image,'upload_img','createImageFromType-$image');
|
|
|
|
|
|
|
+ outFileLog($image ? 'success' : 'failed', 'upload_img', 'createImageFromType-result');
|
|
|
return $image;
|
|
return $image;
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
} catch (Exception $e) {
|
|
|
|
|
+ outFileLog('图片处理异常: ' . $e->getMessage(), 'upload_img', 'createImageFromType-exception');
|
|
|
throw new Exception('图片处理失败: ' . $e->getMessage());
|
|
throw new Exception('图片处理失败: ' . $e->getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|