开发者

why width and height of image is not able to get in php

i am uploading image to s3 server and by php i am making a copy of that image on server , if i upl开发者_运维技巧oad 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


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 GD Allowed memory size exhausted


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜