有人能帮帮我吗?几乎所有的头发都不见了。我有一个问题,试图上传大图片到一个网站。从那以后我就把这个修好了,一切似乎都很顺利。我已经用10Mb+的JPEG文件测试了我的脚本,所有这些看起来都很完美。然而,我刚刚尝试上传一个JPEG从某人的手机(4.9Mb),我得到一个500错误。看看PS中的图片,尺寸是1054 PS,到了1874 PS,高达72 the。有谁能帮我解释一下为什么这是个问题,我是如何解决这个问题的?如果我把图片变小(700 If宽),它上传的很好吗?
有人也有同样的问题吗?下面是我的代码,它旋转图像(一些手机上传后会倒转),然后调整大文件的大小,以便于存储。我测试过的所有照片似乎都有效..。除了这幅画外,还有一幅宽得愚蠢的画!谁来帮帮忙!
$file_name = $_FILES['newPicture']['tmp_name'];
correctImageOrientation($file_name);
AdjustPicSize($file_name);
function correctImageOrientation($file_name) {
if (function_exists('exif_read_data')) {
$exif = exif_read_data($file_name);
if($exif && isset($exif['Orientation']) || !isset($exif['Orientation'])) {
$orientation = $exif['Orientation'];
if($orientation != 1){
$img = imagecreatefromjpeg($file_name);
$deg = 0;
switch ($orientation) {
case 3:
$deg = 180;
break;
case 6:
$deg = 270;
break;
case 8:
$deg = 90;
break;
}
if ($deg) {
$img = imagerotate($img, $deg, 0);
}
// then rewrite the rotated image back to the disk as $filename
imagejpeg($img, $file_name, 95);
} // if there is some rotation necessary
} // if have the exif orientation info
} // if function exists
}
function AdjustPicSize($file_name)
{
$maxDim = 800;
list($width, $height, $type, $attr) = getimagesize( $file_name );
if ( $width > $maxDim || $height > $maxDim ) {
$target_filename = $file_name;
$ratio = $width/$height;
if( $ratio > 1) {
$new_width = $maxDim;
$new_height = $maxDim/$ratio;
} else {
$new_width = $maxDim*$ratio;
$new_height = $maxDim;
}
$src = imagecreatefromstring( file_get_contents( $file_name ) );
$dst = imagecreatetruecolor( $new_width, $new_height );
imagecopyresampled( $dst, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
imagejpeg( $dst, $target_filename ); // adjust format as needed
}
}请你也温柔点,我对这一切有点陌生!
发布于 2017-11-11 16:51:00
这是内存限制问题,您可能想要增加它或考虑使用图像魔法。GD使用RAM存储数据,并从5 MB文件(大尺寸)创建新资源,这将耗费您的内存。
https://stackoverflow.com/questions/47240353
复制相似问题