# Image size formating: What is the best way to do it?

**URL:** <https://discourse.processing.org/t/image-size-formating-what-is-the-best-way-to-do-it/22104>\
**Category:** Coding Questions\
**Created:** [June 23, 2020, 4:05pm UTC](https://discourse.processing.org/t/image-size-formating-what-is-the-best-way-to-do-it/22104 "2020-06-23T16:05:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AntiViral\_Builder](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@AntiViral\_Builder](https://discourse.processing.org/u/AntiViral_Builder)\
**Post date:** [June 23, 2020, 4:05pm UTC](https://discourse.processing.org/t/image-size-formating-what-is-the-best-way-to-do-it/22104/1 "2020-06-23T16:05:19Z")

</div>

This is not an AI question, but what I want to do is to take an image containing a character and format it to the size that my AI will accept which is 32,32. the problem is that when I use this:

for (int i=0;i\<32;i++){  
for (int j=0;j\<32;j++){  
col = img1.get(left + j \* scax, top + i \* scay);  
img2.set(j,i,col);  
}  
}

The result is that the left side of the image is cut off

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 23, 2020, 9:54pm UTC](https://discourse.processing.org/t/image-size-formating-what-is-the-best-way-to-do-it/22104/2 "2020-06-23T21:54:56Z")

</div>

> [@AntiViral\_Builder](#):
>
> The result is that the left side of the image is cut off

Depending on the value of “left” you start reading from img1 not at pos 0 but at pos “left” (e.g. 17).  
Set left to 0. 😉

By the way, did you look at the command `resize()` in the reference?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 23, 2020, 10:02pm UTC](https://discourse.processing.org/t/image-size-formating-what-is-the-best-way-to-do-it/22104/3 "2020-06-23T22:02:53Z")

</div>

> [@AntiViral\_Builder](#):
>
> scax

Depending on value of scax and scay (3) you also maybe read only  
the 3rd or so pixel of the img1. So the resulting image is a very rough copy.

Alternatively, you could average the colors of all pixels in each rectangle between 0,0 and scax,scay and repeat this for all rectangles in img1.  
But there must be articles about this.  
(see [Image scaling - Wikipedia](https://en.wikipedia.org/wiki/Image_scaling)  
This article is wrong: [Image compression - Wikipedia](https://en.wikipedia.org/wiki/Image_compression) )

Chrisir
