为什么php无法获取图像的宽度和高度
我正在将图像上传到 s3 服务器,并通过 php 在服务器上复制该图像, 如果我上传 2.3 mb 的图像,则图像的宽度不会出现,但如果我上传的图像尺寸小于 26kb,则它会显示图像的宽度,以便能够创建副本。
这是我的 php 代码:
$s3 = new S3(awsAccessKey, awsSecretKey);
$thumbId = uniqid();
$thumbId .= ".jpg";
$img = '';
if($imgType == "image/jpeg"){
$img = imagecreatefromjpeg($sourceUrl);
}else if($imgType == "image/png"){
$img = imagecreatefrompng($sourceUrl);
}else if($imgType == "image/gif"){
$img = imagecreatefromgif($sourceUrl);
}else{
$img = imagejpeg($sourceUrl);
}
echo $width = imagesx( $img );
echo $height = imagesy( $img );
请告诉我图像大小有什么问题..
问候
拉胡尔
i am uploading image to s3 server and by php i am making a copy of that image on server ,
if i upload an image of 2.3 mb than the width of image is not coming but if i upload less size image like 26kb than it is showing the width of image so it is able to create the copy .
here is my code of php :
$s3 = new S3(awsAccessKey, awsSecretKey);
$thumbId = uniqid();
$thumbId .= ".jpg";
$img = '';
if($imgType == "image/jpeg"){
$img = imagecreatefromjpeg($sourceUrl);
}else if($imgType == "image/png"){
$img = imagecreatefrompng($sourceUrl);
}else if($imgType == "image/gif"){
$img = imagecreatefromgif($sourceUrl);
}else{
$img = imagejpeg($sourceUrl);
}
echo $width = imagesx( $img );
echo $height = imagesy( $img );
please tell me what is the problem with size of image..
regards
rahul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可能是错的,但我相当确定这是一个内存问题,由于错误报告的某些方面已关闭,因此不会显示出来。
或者是 2.3 MB 的图像已损坏,或者是 GD 无法读取的格式 - 确保您尝试使用各种图像。
如果是内存问题,这里有一个相关问题。
I can be wrong, but I am fairly sure this is a memory issue that doesn't get displayed because some aspect of error reporting is turned off.
Either that, or the 2.3 MB image is broken or in a format that GD can't read - make sure you try it with various images.
If it's a memory issue, here is a related question.
阅读此链接: PHP 重建图像:内存使用
正如 riky 所说,设置内存限制如果可以的话可以更高。还要意识到尺寸比文件大小更重要(因为文件大小适用于压缩图像)。当您在 GD 中打开图像时,每个像素都会分配 3-4 个字节,RGB 和可能的 A。因此,您的 4912px x 3264px 图像需要使用 48,098,304 到 64,131,072 字节的内存,此外还有开销和任何其他内存脚本正在使用。
Read this link: PHP rebuilding images: memory usage
As riky said, set the memory limit higher if you can. Also realize that the dimensions are more important than the file size (as the file size is for a compressed image). When you open an image in GD, every pixel gets 3-4 bytes allocated to it, RGB and possibly A. Thus, your 4912px x 3264px image needs to use 48,098,304 to 64,131,072 bytes of memory, plus there is overhead and any other memory your script is using.