Image Rotate throws error on odd number or odd size image

Description

This issue originally started on a forum post. https://dev.lucee.org/t/image-rotate/5374/4

We thought we had this resolved but I was informed that there were still issues with the image rotate functionality. I was provide with a couple of images that were acting up when we tried to rotate right (i.e. 90 degrees) despite the fact that I had the fix in place. I spent some time trying to figure out why some images worked fine and some didn’t, trying .png files instead of .jpg and then larger files rather than smaller but it all seemed rather random. Finally I noticed that the images that were throwing the exception had one thing in common, the dimensions that were not even.

To test my hunch I went to the Lucee documentation on image rotate since they had code that you could run. I modified the code on that page to create an image that is 100x99 rather than 100x100 and then ran it with rotation angles of 270 (rotate left) and 90 (rotate right) and sure enough the rotate right throws the exception. I’ve provided the link and screen shots of each below.

I also tried this:

<cfscript> img=imageNew("",100,87,"RGB","0fb9b1"); imageRotate(img, "90"); cfimage(action="writeToBrowser",source=img); </cfscript>

When this happens it throws an error;
Error:
java.lang.ArrayIndexOutOfBoundsException You can try this yourself here.

https://docs.lucee.org/reference/functions/imagerotate.html

My issue is that some of our users may not upload a perfectly dimensioned image. And it seems that only Odd numbers have the issue. If you change to an even number the image rotates fine.

Environment

This also effects the latest version of Lucee
Version Lucee 5.2.9.31
Version Name Velvet
Release date Sep 17, 2018
ColdFusion® compatibility version 2016.0.03.300357
OS Windows Server 2016 (10.0) 64bit
Servlet Container Apache Tomcat/8.5.28
Java 1.8.0_191 (Oracle Corporation) 64bit
Architecture 64bit

Attachments

1
  • 12 Apr 2019, 03:23 am

Activity

Show:

Pothys - MitrahSoft 23 April 2019 at 13:53

I've checked it confirmed the issue happened on lucee. ACF returns as expected. Also I tried with your sample code, Got a error that was differ from you. that is

lucee.runtime.exp.NativeException: 1944 at com.sun.media.jai.opimage.AffineNearestOpImage.intLoop(AffineNearestOpImage.java:921) at com.sun.media.jai.opimage.AffineNearestOpImage.computeRect(AffineNearestOpImage.java:279) at com.sun.media.jai.opimage.AffineOpImage.computeTile(AffineOpImage.java:626)

KabutoTX 12 April 2019 at 02:44

Playing some more. Did notice one of my images was getting a 1 pixel black border @ 90 angle. It is caused by the centering x and y. I just 0F them and problem went away on my JPG. For my PNG I had to remove the Border Hints for (alpha != null) section. You can keep the KEY_REPLACE_INDEX_COLOR_MODEL hint but JAI automatically TRUEs it by default.

BTW ACF 2018 threw an error on my PNG using bicubic or bilinear @145 angle where my code works fine. slightly smiling face

KabutoTX 11 April 2019 at 18:43

FYI. Taking the KEY_BORDER_EXTENDER hint off stops the error.

Fixed

Details

Assignee

Reporter

Priority

Fix versions

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Sprint

Affects versions

Created 9 April 2019 at 17:31
Updated 24 September 2020 at 08:25
Resolved 16 August 2019 at 06:08

Flag notifications