Here is a new function for rotation of PNG files, which should fix your issue, if you pass it a file with no transparency or alphait returns an error to you
If you do SMGetVariable("cm") after running it you will see the color model Java thinks the file has
// RotatePNG ( imgLocation ; degrees )
// v1.0
// 19_03_12 JR
import javax.imageio.ImageIO
import java.awt.image.BufferedImage
import java.awt.Graphics2D
import java.awt.geom.AffineTransform
import java.awt.RenderingHints
isTransparent = {image, x, y ->
pixel = image.getRGB(x,y)
return (pixel>>24) == 0x00
}
containsTransparency = { image ->
for (i in 0..<image.getHeight()) {
for (j in 0..<image.getWidth()) {
if (isTransparent(image, j, i)){
return true
} //end if
} //end for
} //end for
} //end containsTransparency
containsAlphaChannel ={ image ->
return image.getColorModel().hasAlpha()
}//end containsAlphaChannel
degrees = Double.parseDouble(degrees)
radians = Math.toRadians(degrees)
isRightAngle = degrees % 90 == 0
BufferedImage img
if (imgLocation.indexOf("://") != -1) {
img = ImageIO.read(new URL(imgLocation))
} else {
img = ImageIO.read(new File(imgLocation))
}
cm = img.getColorModel()
//check for transparency
try{
isAlpha = containsAlphaChannel(img)
if ( !isAlpha) {
isTransparent = containsTransparency(img)
if ( !isTransparent){
return 'ERROR - no transparency'
}//end if
return 'ERROR - no transparency'
} //end if
} catch (e) {
return 'ERROR - unspecified'
}
int newWidth = Math.abs(Math.cos(radians) * img.getWidth()) + Math.abs(Math.sin(radians) * img.getHeight())
int newHeight = Math.abs(Math.cos(radians) * img.getHeight()) + Math.abs(Math.sin(radians) * img.getWidth())
at = AffineTransform.getRotateInstance(radians, img.getWidth()/2, img.getHeight()/2)
type = BufferedImage.TYPE_INT_ARGB
dest = new BufferedImage(newWidth, newHeight, type)
g2d = dest.createGraphics()
if (!isRightAngle) {
// enable antialiasing for odd angles
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
g2d.setTransform(AffineTransform.getTranslateInstance((newWidth - img.getWidth()) / 2, (newHeight - img.getHeight()) / 2))
g2d.drawImage(img, at, null)
return dest
So only two parameters as you don't care about background colour