fuel/core — pull request #1206 by quetzyg (2012-11-15 11:25:09+00:00)
Title: Update classes/image/gd.php

So I dug a bit further and found out that the unrecoverable error in GB/JPEG library isn't caused by a missing image channel info, although that was the only pattern I was getting at first.

If we set persistence to false (default) in the Image class config, it will call reload() after save/output.

The problem occurs when we save/output a different image format from the one we loaded first (i.e. load a PNG and save/output a JPG).

When loading a PNG and saving a JPG, we have:

On the first load() call:

file: test.png
called method: imagecreatefrompng()
$this->image_extension = 'png'
$image_extension = 'png'

On the second load() call (during save() / called by reload()):

file: test.png
called method: imagecreatefromjpeg()
$this->image_extension = 'jpg'
$image_extension = 'jpeg'

The unrecoverable error happens because on the second load() the class tries to open a PNG with imagecreatefromjpeg().

Since I don't know if this is intended behaviour or not, my proposal is to supress the error to avoid the script from failing, and throw a Runtime Exception so we can gracefuly handle the problem.