简体   繁体   中英

getimagesize() not working on php 5.6?

I have a php script that gets a base64 string from an ajax request and then I use the getimagesize($image) to obtain its size. This was working properly on php 5.3 but now that I'm running php 5.6 this doesn't seem to work.

$image = $this->input->post('image');
$info = getimagesize($image);

Well as been said by @Barman I guess php 5.6 it's more strict in the use of the getimagesize() function. I got it working by making a temporary image, pasting it inside my pdf document and then deleting it.

    $image = $this->input->post('image');
    $dataURI    = $image;
    $dataPieces = explode(',',$dataURI);
    $encodedImg = $dataPieces[1];
    $decodedImg = base64_decode($encodedImg);

    //  Check if image was properly decoded
    if( $decodedImg!==false )
    {
        //  Save image to a temporary location
        if( file_put_contents(TEMPIMGLOC,$decodedImg)!==false )
        {

            $pdf->AddPage("L");
            $pdf->centreImage(TEMPIMGLOC);

            //  Delete image from server
            unlink(TEMPIMGLOC);
        }
    }

Needless to said the centreImage its a custom function inside my pdf class that just centers the image in the new page.

Thanks everyone for the feedback and info, I will dig more into documentation because it's not clear to me how did it work in php 5.3

Just to make it more clear here was the main functions where the getimagesize() was not working.

function resizeToFit($imgFilename) {
    list($width, $height) = getimagesize($imgFilename);
    $widthScale = self::MAX_WIDTH / $width;
    $heightScale = self::MAX_HEIGHT / $height;
    $scale = min($widthScale, $heightScale);
    return array(
        round($this->pixelsToMM($scale * $width)),
        round($this->pixelsToMM($scale * $height))
    );
}
function centreImage($img) {
    list($width, $height) = $this->resizeToFit($img);
    // you will probably want to swap the width/height
    // around depending on the page's orientation
    $this->Image(
        $img, (self::A4_HEIGHT - $width) / 2,
        (self::A4_WIDTH - $height) / 2,
        $width,
        $height
    );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM