# Save data into PNG image file

**URL:** <https://ziggit.dev/t/save-data-into-png-image-file/6602>\
**Category:** Help\
**Tags:** build-system\
**Created:** [October 30, 2024, 2:09pm UTC](https://ziggit.dev/t/save-data-into-png-image-file/6602 "2024-10-30T14:09:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndrean](https://ziggit.dev/user_avatar/ziggit.dev/ndrean/32/6276_2.png) [@ndrean](https://ziggit.dev/u/ndrean)\
**Post date:** [October 30, 2024, 2:09pm UTC](https://ziggit.dev/t/save-data-into-png-image-file/6602/1 "2024-10-30T14:09:47Z")

</div>

Not sure if this is the right place to post, or maybe Discord?.. Please tell me if this is inappropriate!

I want to save data into a PNG file with [zigimg](https://github.com/zigimg/zigimg).

My data is a slice `[]u8` of consecutive triplets {r,g,b} of u8. I want to transform this into a PNG image file.

I don’t see how to do this. My code below fails on the last line of `image` as built with `fromRawPixels` is probably wrong but I don’t see what else could I use.

```zig
var image = try zigimg.Image.fromRawPixels(allocator, w, h, pixels, .rgb24);
defer image.deinit();

print("check pixels: {}", .{pixels.len}); // w= 100 x h = 200 x 3 = 60_000 ok

try image.writeToFilePath("junk.png", .{ .png = .{} });

```

---

<div class="post-metadata">

**Author:** ![LucasSantos91](https://ziggit.dev/user_avatar/ziggit.dev/lucassantos91/32/440_2.png) [@LucasSantos91](https://ziggit.dev/u/LucasSantos91)\
**Post date:** [October 30, 2024, 2:51pm UTC](https://ziggit.dev/t/save-data-into-png-image-file/6602/2 "2024-10-30T14:51:56Z")

</div>

Does it fail to compile or do you get a runtime error? What error do you get?

---

<div class="post-metadata">

**Author:** ![ndrean](https://ziggit.dev/user_avatar/ziggit.dev/ndrean/32/6276_2.png) [@ndrean](https://ziggit.dev/u/ndrean)\
**Post date:** [October 30, 2024, 3:24pm UTC](https://ziggit.dev/t/save-data-into-png-image-file/6602/3 "2024-10-30T15:24:33Z")

</div>

It fails to compile, corresponding to line 96 in zigimg/imageunmanaged,

```zig
error: no field named 'struct' in enum '@typeInfo(builtin.Type).Union.tag_type.?'

```

I understand that my entry is not the struct the function `writeToFilePath` wants. So `image` must be badly built.

---

<div class="post-metadata">

**Author:** ![Calder-Ty](https://ziggit.dev/user_avatar/ziggit.dev/calder-ty/32/10237_2.png) [@Calder-Ty](https://ziggit.dev/u/Calder-Ty)\
**Post date:** [October 30, 2024, 3:35pm UTC](https://ziggit.dev/t/save-data-into-png-image-file/6602/4 "2024-10-30T15:35:58Z")

</div>

What version of the compiler are you using?

---

<div class="post-metadata">

**Author:** ![ndrean](https://ziggit.dev/user_avatar/ziggit.dev/ndrean/32/6276_2.png) [@ndrean](https://ziggit.dev/u/ndrean)\
**Post date:** [October 30, 2024, 3:44pm UTC](https://ziggit.dev/t/save-data-into-png-image-file/6602/5 "2024-10-30T15:44:24Z")

</div>

version 0.13, and I fetched zigimg from the github, latest

I rather think my code is wrong, not the compiler nor the library. Its more that I don’t understand how to use this library.

---

<div class="post-metadata">

**Author:** ![Calder-Ty](https://ziggit.dev/user_avatar/ziggit.dev/calder-ty/32/10237_2.png) [@Calder-Ty](https://ziggit.dev/u/Calder-Ty)\
**Post date:** [October 30, 2024, 3:54pm UTC](https://ziggit.dev/t/save-data-into-png-image-file/6602/6 "2024-10-30T15:54:07Z")

</div>

It’s not that the compiler is wrong, its that there is a version mismatch. It looks like zigimg latest targets the latest version of the compiler. There was a change into the names of the types in the `std.builtin.Type` enum between version 0.13 and 0.14.0.dev, where the names (like `struct` were changed from uppercase to lower case). You’ll need to get a version of the compiler that matches what zigimg supports.

---

<div class="post-metadata">

**Author:** ![ndrean](https://ziggit.dev/user_avatar/ziggit.dev/ndrean/32/6276_2.png) [@ndrean](https://ziggit.dev/u/ndrean)\
**Post date:** [October 30, 2024, 4:10pm UTC](https://ziggit.dev/t/save-data-into-png-image-file/6602/7 "2024-10-30T16:10:51Z")

</div>

Ah ok! So I installed version: 0.14.0-dev.183+b2e89d and my code seems to work.  
Thanks!
