imageapi_image_overlay() fails under PHP 5.3 as it passes a copy (vs a reference) to the image when invoking imageapi_toolkit_invoke(). This exhibits as HTTP 500 errors for any imagecache preset that uses a overlay watermark action.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

thsutton’s picture

The attached patch changes imageapi_image_overlay() to pass $image by reference to resolve HTTP 500 errors for imagecache presets which use an overlay watermark action.

modctek’s picture

+1, this issue was driving me crazy, trying to figure out why my overlays weren't working.

SchwebDesign’s picture

THANK YOU!!! subscribing- this was driving me crazy as well and the patch fixed the issue for me.

These are the errors I was getting:

Parameter 2 to imageapi_gd_image_overlay() expected to be a reference, value given in /home/familype/public_html/sites/all/modules/imageapi/imageapi.module on line 165.
action(id:4): canvasactions_file2canvas failed for sites/default/files/imagecache_sample.png
Failed generating an image from imagecache_sample.png using imagecache preset large-watermark.

ImageAPI 6.x-1.10
ImageAPI GD2 6.x-1.10
ImageCache 6.x-2.0-beta12
Imagecache Canvas Actions 6.x-2.0

GD library bundled (2.0.34 compatible)

Drupal 6.22
MySQL database 5.1.56
PHP 5.3.6

2020media’s picture

Blimey this was a hard one to track down - I was getting no errors in the logs and I couldn't figure out why some imagecache presets were working and not others - eventually found it was related to overlay watermark and hence found this post. The site was migrated from a PHP5.2 server to a PHP5.3 server. Your solution worked perfectly.

Thank you thsutton.

garbo’s picture

The solution worked for me too! But imagecache_actions isn't the only module that's have troubles with PHP5.3. I wonder why so many modules are having troubles with PHP 5.3 and the reference object.

thsutton’s picture

Because code that shouldn't have worked but did in PHP 5.2 now correctly doesn't work in PHP 5.3.

thsutton’s picture

Status: Active » Needs review
crea’s picture

The fix #1 works for me but in latest 2.x this is now in a different file: imageapi_image_overlay.inc

joelstein’s picture

Version: 6.x-2.0 » 6.x-1.8
Status: Needs review » Reviewed & tested by the community

The patch in #1 worked for me.

alphex’s picture

Status: Reviewed & tested by the community » Needs work
FileSize
39.52 KB

Running PHP 5.3.8.

This is still an issue for us. Has anyone had any luck with PHP 5.3.8 and this solution?
We're running version 1.8 of the module as well.

Does 2.0 fix this?

ImageAPI 6.x-1.10
ImageAPI GD2 6.x-1.10
ImageCache 6.x-2.0-beta12
Imagecache Canvas Actions 6.x-1.8

On D6.22
PHP 5.3.8
Apache/2.2.15 (Red Hat)

alphex’s picture

Ok, now I'm confused.
I just looked at the patch code, and realized that whats in it is old, cause the 6.x-1.8 module has this fix in it already?
but 1.8 was published in Feb 2011, and this patch wasn't written until May?

I just re-downloaded the module and double checked. If I search for the string
return imageapi_toolkit_invoke('overlay', $image, array(&$layer, $x, $y, $alpha, $reverse));

It shows up at line 134 with the AMPERSAND sign already in place (which is the only difference I saw.

did this not warrant a version number increment? and just got put in the code anyway?

If I'm being blind about something, please educate me :)

dman’s picture

Status: Needs work » Closed (fixed)

IIRC, this fix was trivial, and went in quietly when some other updates were being done, or when it was noticed in the logs during testing some time.
On many PHP installs, the notice can be or is suppressed, so it didn't seem to bite very hard at the time. As more PHP5.3 strict users came online, it became more of an issue, but it was already fixed in -dev branches by then. There is also the chance that it was 'fixed' at one point but overwritten/reverted for a while by a different code merge? I dunno.

There was probably some sore of overlap between the fix actually happening (in dev), this patch being raised to fix something that was already in the 'pending' state, and the 1.8 actual release. Or something like that in a different order.

This is why I'd love to be able to have a testsuite to manage regressions ... but can't do it with images :-(

Anyway, I guess that means the problem is not seen in any of the stable releases out there today?
Meaning... fixed? I think?

TwoD’s picture

Version: 6.x-1.8 » 6.x-2.0
Status: Closed (fixed) » Reviewed & tested by the community

This issue was originally about ImageCache Actions 6.x-2.0, where this issue STILL exists.
The patch in #1 is the correct way to fix this, see my post in #540486-72: Error with PHP 5.3 (ImageAPI) and the patch in #648950-12: Error with PHP 5.3.

The issue was incorrectly fixed by no longer accepting $layer as an argument in ImageCache Actions 6.x-2.x 5ce275a7..., please revert that commit as it could break backwards compatibility (and might decrease performance due to the layer having to be copied - also, it's technically valid to modify the layer in the ImageAPI 'overlay' callback).

I can confirm the #1 patch fixes ImageCache on PHP 5.3 (images with overlays don't get created at all without it).

fietserwin’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

The 6.x-2.x is not supported anymore and we are closing all issues for it. Please feel free to reopen against the 6.x-1.x branch if the error also appears there.