Question

Hi I have a very strange behaviour of PHP and hope that you are able to help me.

I have a Symfony 1.4 based PHP project on PHP 5.4.7.

I have the following class function to resize images:

public function getResizedImageHorizontal($newWidth) {
    $image = null;
    $data = $this->getData();

    if(strlen($data["image"]) > 0) {
        $image = imagecreatefromstring($data["image"]);
        $newHeight = intval(imagesy($image) / 100) * ($newWidth / (imagesx($image) / 100));
        $newImage = imagecreatetruecolor($newWidth, $newHeight);
        imagecopyresampled($newImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, imagesx($image), imagesy($image));
        ob_start();
        imagejpeg($newImage, null, 100);
        $image = ob_get_contents();
        ob_end_clean();
    }

    var_dump($image);
    return $image;
}

and this is my function call in the template:

$image = $galleryObj->getResizedImageHorizontal(100);
var_dump($image);

Because I get no result from my function (which is working perfectly when I put the code directly in the template) I put 2 vardumps in the codepieces above to explain it more clear:

The first vardump returns me the imagecontent resized (source is blob in the db) as intended, the second one in the template as direct call, has an empty result.

Or in short: directly before the "return" the value is correct: string(9474) "...

But in my template directly after the function call immediately: string(0) ""

What the heck is going on here, did I find some bug in PHP or is it known in combination with Symfony / Doctrine 1.4 by executing stuff from the template?

I cannot get this value passed which is very odd, it is unlikely but maybe someone had the same trouble as me so I thought I should ask here.

Thanks in advance~

Was it helpful?

Solution

I put this problem for a longer while aside because I had something else to do, I now reencountered the problem, found my old post and the comment by Michal Trojanowski perfectly solved it, thanks!

Here is the solution once more:

$image = $galleryObj->getRawValue()->getResizedImageHorizontal(100);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top