# Is there a way to convert a png file to jpg?

**URL:** <https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-png-file-to-jpg/72592>\
**Category:** Ignition\
**Created:** [April 18, 2023, 6:01pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-png-file-to-jpg/72592 "2023-04-18T18:01:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam\_Verellen](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/adam_verellen/32/33321_2.png) [@Adam\_Verellen](https://forum.inductiveautomation.com/u/Adam_Verellen)\
**Post date:** [April 18, 2023, 6:01pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-png-file-to-jpg/72592/1 "2023-04-18T18:01:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 18, 2023, 6:11pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-png-file-to-jpg/72592/2 "2023-04-18T18:11:56Z")

</div>

This Java code will do it:

```auto
BufferedImage img = ImageIO.read(new File("lenna.png"));
ImageIO.write(img, "jpg", new File("lenna.jpg"));

```

Can you manage the conversion to Jython yourself?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 18, 2023, 6:14pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-png-file-to-jpg/72592/3 "2023-04-18T18:14:15Z")

</div>

> [@Adam\_Verellen](#):
>
> ... convert a png file to a jpg file ...

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.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [April 18, 2023, 6:17pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-png-file-to-jpg/72592/4 "2023-04-18T18:17:54Z")

</div>

@Kevin.Herron already beat me to it, but here's the Jython version of it.

```python
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")))

```

---

<div class="post-metadata">

**Author:** ![Adam\_Verellen](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/adam_verellen/32/33321_2.png) [@Adam\_Verellen](https://forum.inductiveautomation.com/u/Adam_Verellen)\
**Post date:** [April 18, 2023, 6:33pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-png-file-to-jpg/72592/5 "2023-04-18T18:33:06Z")

</div>

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](http://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!!
