?
Referenced as Pull Request for: # 5558
avatar jbrouns
jbrouns
30 Dec 2014

When you crop or resize a transparent image (png/gif) with the JImage class, the transparency gets lost. The Joomla CMS does not directly use this class, but I found this out while developing the Form2Content component, which does use these JImage class functions.

Steps to reproduce the issue

With this sample code the issue can be reproduced. Please note that you need to set-up this piece of code in your Joomla environment. There's no way to reproduce this issue through the Joomla GUI.

$src = 'test.png'; // Path to a transparent image
$dstCropped= 'test_cropped.png'; // Path where the cropped image will be written
$dstResized= 'test_resized.png'; // Path where the resized image will be written

$srcImage = new JImage($src);
$dstImage = $srcImage->resize(100, 100, true);
$dstImage->toFile($dstResized, IMAGETYPE_PNG);

$dstImage = $srcImage->crop(100, 100, 0, 0, true);
$dstImage->toFile($dstCropped, IMAGETYPE_PNG);

Expected result

Two transparent images should be generated.
One resized to 100 x 100 pixels and one cropped from the left top, 100 x 100 pixels.

Actual result

The sizes are correct, but you will see that the two generated images have lost their transparency.

System information (as much as possible)

Windows NT XPS-15 6.2 build 9200 (Unknown Windows version Home Premium Edition) i586
PHP Version 5.4.26
Web Server Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.26
Joomla! Version Joomla! 3.3.6 Stable
Joomla! Platform Version Joomla Platform 13.1.0 Stable

Additional comments

I have made a working CLI example to reproduce this issue, but due to the upload restrictions I can't upload it here.

avatar jbrouns jbrouns - open - 30 Dec 2014
avatar infograf768
infograf768 - comment - 31 Dec 2014

PR proposed is here:
#5558

avatar infograf768 infograf768 - close - 31 Dec 2014
avatar zero-24 zero-24 - close - 31 Dec 2014
avatar infograf768 infograf768 - change - 31 Dec 2014
Status New Closed
Closed_Date 0000-00-00 00:00:00 2014-12-31 08:07:45
avatar zero-24 zero-24 - change - 7 Jul 2015
Labels Added: ?

Add a Comment

Login with GitHub to post a comment