Has anyone been able to convert a png file to a jpg file in a gateway script?
I'll update my post if I find something in the meantime. So far no luck.
Thanks in advance.
Has anyone been able to convert a png file to a jpg file in a gateway script?
I'll update my post if I find something in the meantime. So far no luck.
Thanks in advance.
This Java code will do it:
BufferedImage img = ImageIO.read(new File("lenna.png"));
ImageIO.write(img, "jpg", new File("lenna.jpg"));
Can you manage the conversion to Jython yourself?
It's generally not useful. PNG is a lossless file format. JPG is lossy and will have artifacts. The only reason I can think of to do this is for low-resolution / accuracy archiving of images to save disk space.
@Kevin.Herron already beat me to it, but here's the Jython version of it.
from javax.imageio import ImageIO
from java.io import File
img = ImageIO.read(File(path.format("lenna.png")))
ImageIO.write(img, 'jpg', File(path.format("lenna.jpg")))
Thank you @Kevin.Herron and @JordanCClark unfortunatelyI can only pick one solution. But both helped a ton.
Exactly what I needed. Here is my end snippet
from javax.imageio import ImageIO
from java.io import File
img = ImageIO.read(File('C:\images\image.png'))
ImageIO.write(img, 'jpg', File('C:\images\image.jpg'))
@Transistor - While I agree with you. The file I get from my frame grabber only gives a PNG file. Using I'm using Sherlock to perform an inspection on the file to verify orientation of a reverse camera, it only accepts jpeg files.
You guys saved me a giant headache. Thanks!!