# Is there any way to crop an image in code?

**URL:** <https://forum.makecode.com/t/is-there-any-way-to-crop-an-image-in-code/3907>\
**Category:** Help\
**Created:** [October 16, 2020, 3:25am UTC](https://forum.makecode.com/t/is-there-any-way-to-crop-an-image-in-code/3907 "2020-10-16T03:25:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GameGod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gamegod/32/2756_2.png) [@GameGod](https://forum.makecode.com/u/GameGod)\
**Post date:** [October 16, 2020, 3:25am UTC](https://forum.makecode.com/t/is-there-any-way-to-crop-an-image-in-code/3907/1 "2020-10-16T03:25:12Z")

</div>

What the title says.

---

<div class="post-metadata">

**Author:** ![GameGod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gamegod/32/2756_2.png) [@GameGod](https://forum.makecode.com/u/GameGod)\
**Post date:** [October 16, 2020, 3:27am UTC](https://forum.makecode.com/t/is-there-any-way-to-crop-an-image-in-code/3907/2 "2020-10-16T03:27:16Z")

</div>

Nevermind! found it!

---

<div class="post-metadata">

**Author:** ![GameGod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gamegod/32/2756_2.png) [@GameGod](https://forum.makecode.com/u/GameGod)\
**Post date:** [October 16, 2020, 3:18pm UTC](https://forum.makecode.com/t/is-there-any-way-to-crop-an-image-in-code/3907/3 "2020-10-16T15:18:59Z")

</div>

The way I do it causes **LOTS** of lag. Can you give me other ways?

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [October 16, 2020, 3:46pm UTC](https://forum.makecode.com/t/is-there-any-way-to-crop-an-image-in-code/3907/4 "2020-10-16T15:46:16Z")

</div>

Well, can you show us your way? You might have a memory bug in your code or something, which might be why it’s slowing down massively.

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [October 16, 2020, 6:31pm UTC](https://forum.makecode.com/t/is-there-any-way-to-crop-an-image-in-code/3907/5 "2020-10-16T18:31:05Z")

</div>

Calling set pixel on individual pixels would be slow, but if you do fillRect 4 times (one for each side) it will probably be a lot faster.

something like

```auto
image.fillRect(0, 0, screen.width, minCropY, 0)
image.fillRect(0, maxCropY, screen.width, screen.height - maxCropY, 0)
image.fillRect(0, 0, minCropX, screen.height, 0)
image.fillRect(maxCropX, 0, screen.width - maxCropX, screen.height, 0)

```
