简体   繁体   English

getimagesize()在php 5.6上不起作用?

[英]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. 我有一个PHP脚本,它从ajax请求中获取base64字符串,然后使用getimagesize($ image)获取其大小。 This was working properly on php 5.3 but now that I'm running php 5.6 this doesn't seem to work. 这在php 5.3上正常工作,但是现在我在运行php 5.6,这似乎不起作用。

$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. 就像@Barman所说的那样,我猜php 5.6在使用getimagesize()函数时更加严格。 I got it working by making a temporary image, pasting it inside my pdf document and then deleting it. 我通过制作一个临时图像,将其粘贴到我的pdf文档中,然后将其删除来使其工作。

    $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. 不用说centerImage它是我的pdf类中的一个自定义函数,它只是将图像居中在新页面中。

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 感谢大家的反馈和信息,我将深入研究文档,因为尚不清楚它在php 5.3中如何工作

Just to make it more clear here was the main functions where the getimagesize() was not working. 为了使这里更清楚,主要功能是getimagesize()无法正常工作。

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
    );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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