# Generating a live Jpeg from random numbers

**URL:** <https://discourse.processing.org/t/generating-a-live-jpeg-from-random-numbers/6066>\
**Category:** Coding Questions\
**Created:** [November 29, 2018, 10:37am UTC](https://discourse.processing.org/t/generating-a-live-jpeg-from-random-numbers/6066 "2018-11-29T10:37:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![glegassick](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@glegassick](https://discourse.processing.org/u/glegassick)\
**Post date:** [November 29, 2018, 10:37am UTC](https://discourse.processing.org/t/generating-a-live-jpeg-from-random-numbers/6066/1 "2018-11-29T10:37:57Z")

</div>

Hi,

I am new to the community and new to Processing and have a project in mind that I would like to tackle in order to learn.

I would like to generate a “live” jpeg image from random number inputs. I am aware that the Jpeg will need a vanilla header and that the result will look like a totally “corrupt” image - but this is exactly what I am after!

I have found Antonio Roberts version online using Pure Data ([https://www.hellocatfood.com/create-jpgs-in-pure-data/](https://www.hellocatfood.com/create-jpgs-in-pure-data/)) and was wondering whether this could be recreated in Processing? And to top it off, would it be possible to preview the jpeg generating live as data is entered?

Any help, pointers and recommendations of where I can start to research this would be very much appreciated!

Thanks!

Grant

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 29, 2018, 10:54am UTC](https://discourse.processing.org/t/generating-a-live-jpeg-from-random-numbers/6066/2 "2018-11-29T10:54:25Z")

</div>

there are 2 things involved:

- set a “point” to random color
- save that picture to a jpg file

[https://processing.org/reference/set\_.html](https://processing.org/reference/set_.html)  
[https://processing.org/reference/save\_.html](https://processing.org/reference/save_.html)

![test](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/aaa6309c673e1c4676df5ab4de81c4187a3c434e.jpeg)

show your code pls.

---

<div class="post-metadata">

**Author:** ![glegassick](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@glegassick](https://discourse.processing.org/u/glegassick)\
**Post date:** [November 29, 2018, 11:19am UTC](https://discourse.processing.org/t/generating-a-live-jpeg-from-random-numbers/6066/3 "2018-11-29T11:19:00Z")

</div>

Thanks for the reply!

Surely this will render a (random) pixelated image as opposed to a “corrupt” jpeg image using random JPEG encoded (JFIF) bytes?

Also, the idea is to write random (binary) data into a file (with a jpeg header) to render out the jpeg generation process live - not to save it out as a rendered image to view.

![corrupt%20jpeg](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/3674c954766813f12865fdb0dbc2c3fdf36f0f1b.jpeg)

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 29, 2018, 12:02pm UTC](https://discourse.processing.org/t/generating-a-live-jpeg-from-random-numbers/6066/4 "2018-11-29T12:02:07Z")

</div>

you could try to read a existing jpg file,  
( and also show it  
[https://processing.org/reference/loadImage\_.html](https://processing.org/reference/loadImage_.html)  
)

but use:  
[https://processing.org/reference/loadBytes\_.html](https://processing.org/reference/loadBytes_.html)

change bytes at positions what are outside the file definition area  
and use:  
[https://processing.org/reference/saveBytes\_.html](https://processing.org/reference/saveBytes_.html)  
to save it back.

that could be a start??

---

<div class="post-metadata">

**Author:** ![glegassick](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@glegassick](https://discourse.processing.org/u/glegassick)\
**Post date:** [November 29, 2018, 12:10pm UTC](https://discourse.processing.org/t/generating-a-live-jpeg-from-random-numbers/6066/5 "2018-11-29T12:10:59Z")

</div>

Thanks for this! Will have a look and see what I can achieve.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [December 6, 2018, 10:17pm UTC](https://discourse.processing.org/t/generating-a-live-jpeg-from-random-numbers/6066/6 "2018-12-06T22:17:32Z")

</div>

> [@glegassick](#):
>
> Surely this will render a (random) pixelated image as opposed to a “corrupt” jpeg image using random JPEG encoded (JFIF) bytes?

~ 2004 Benjamin Gaulon wrote a PHP JPEG corrupter, and it was adapted into a Processing sketch by Jeni5 in 2016. I helped adapt an interactive version. It is posted in the old forum; you may find it useful:

[https://forum.processing.org/two/discussion/comment/77288/#Comment\_77288](https://forum.processing.org/two/discussion/comment/77288/#Comment_77288)

![](https://yyz2.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/13ae43cad41d8ffda29eb822db83e18940fa5de4.png)
