PngLib - Extract data from png files (width, height, color depth etc)

a version that could read the rotation of an jpg image taken with the iphone camera would have been great. Still trying to figure out a workaround for the bug when saveing the photo with display.save and full res and corona dosent register the orientation of the photo. [import]uid: 17969 topic_id: 26389 reply_id: 107467[/import]

and while we are at it, EXIF and IPTC fetching would be most useful…

[import]uid: 19626 topic_id: 26389 reply_id: 107493[/import]

EXIF is what causes a problem with the function I keep posting. It assumes a rather plain JFIF file for no particularly good reason. EXIF is more than an info block, it’s a wrapper specification that *happens* to encapsulate a compressed JPEG image. However it’s quite similar to the JFIF format except it has a APP1 segment instead of the APP0 segment the function looks for. If you remove the assert at line 39 it should prevent the function from throwing an exception for EXIF files. With that out of the way, you *should* be able to read most of the species of JPEG wrappers that use an APPn, n > 0 segment.

If you wanted to yank fields from the EXIF segment, you could do something like this between 38 and 42:

[lua] local jpegEXIF = string.char( 255 ) … string.char( 225 ) – 0xFFE1

local wrapperMarker = fileHandle:read(2)
local wrapperMarkerReadHead = fileHandle:seek()
if wrapperMarker == jpegAPP0 then
–this is a JFIF file
elseif wrapperMarker == jpegEXIF then
–this is an EXIF file
–[[ here you could read the EXIF header info, e.g., orientation
and return to wrapperMarkerReadHead before continuing
–]]
end[/lua]

You’d need a better way to differentiate the main image from any embedded thumbnail for this to be general-purpose quality. The size of multi-megapixel images is probably too much of a performance hit to scan the whole file two bytes at a time looking for SOF segment markers. [import]uid: 44647 topic_id: 26389 reply_id: 107534[/import]

any progress on this?

what about .tif, .tiff, jpeg, jpg?

OR is there another way to find out the width/height of a saved image? [import]uid: 90610 topic_id: 26389 reply_id: 126235[/import]

any progress on this?

what about .tif, .tiff, jpeg, jpg?

OR is there another way to find out the width/height of a saved image? [import]uid: 90610 topic_id: 26389 reply_id: 126235[/import]

@Danny,
I was very excited to find this library! I got it all setup and working with my app in the simulator, then I noticed that on my android device it didn’t work anymore. On my iPad it does work just fine. I ran logCat to see what the matter was and I am getting this error:

11-25 16:18:26.151 I/Corona (30377): Lua Runtime Error: lua_pcall failed with status: 2, error message is: C:\Users\rxmar_000\Desktop\BOM\scripts\pngLib.lua:34: images/story1/page1/item1.png: No such file or directory

Is it normal that it would be looking at my desktop computers directory path for files even when being run on my Android device? So the issue is its failing to find my “image” files on the Android device, any idea why this is happening? [import]uid: 19620 topic_id: 26389 reply_id: 132356[/import]

@rxmarccall,

If you resolve this, please post your resolution. I too ran into an issue on Android (Kindle Fire and Nexus 7) with pnglib. I haven’t had to debug however.

(Of course, if I get to it first, I’ll post back.) [import]uid: 110228 topic_id: 26389 reply_id: 132374[/import]

@emaurina,
glad I’m not the only one seeing this issue. I hope we can get this resolved because this library has made my app WAY more effecient in handling images. Maybe the original poster might have some ideas as well? [import]uid: 19620 topic_id: 26389 reply_id: 132378[/import]

Guys,

Remember that system.DocumentsDirectory doesn’t exist on android:

http://www.coronalabs.com/blog/2012/09/26/faq-wednesday-ios-builds-api-docs-and-android/

file://localhost/Users/dcgm1986/Programming/Projects/iOS/Corona/Other/Api-Web-Daily/html/api/library/system/pathForFile.html

(see gotchas)

So if thats where your attempting to get a png file via png lib, thats your issue (on Android)
[import]uid: 84637 topic_id: 26389 reply_id: 132393[/import]

Danny,

Thanks for writing so quickly. To be clear, I ran into a case where pnglib failed to find the width/height of a png that was in the ResourcesDirectory.

However…

I was in a hurry so I skipped using pngLib at the time and input the values manually. The mistake could well have been mine, but beyond basic debugging, time constraints force me to skip using it for then.

I’ll have to try again and debug more later. I do want to use this resource more.

So, thanks for the support and for this this resource.

Cheers,
Ed [import]uid: 110228 topic_id: 26389 reply_id: 132419[/import]

@Danny,
Dang so the short answer is that this library will work with IOS only right? I read the first link you posted and thats what I gathered, that really sucks. (second link is broken). Guess its back to putting in all my png’s width and height by hand! [import]uid: 19620 topic_id: 26389 reply_id: 132433[/import]

@rxmarcall:

I wouldn’t go that far. It depends on your usage I guess. For instance, on my own project I don’t load any images from the documents directory so it’s fine.

I will see what I can do about the android side of it when I have some time. [import]uid: 84637 topic_id: 26389 reply_id: 132436[/import]

I don’t think I do either? I guess I am confused on how that works. I just have my images in a sub folder called “images” on the root of my project. When I build my project do those images get put in the “documents directory”? I am not trying to do anything special, these are just basic images I use in my project. [import]uid: 19620 topic_id: 26389 reply_id: 132438[/import]

In that case this should work for you fine.

Isn’t it working for you? :slight_smile: [import]uid: 84637 topic_id: 26389 reply_id: 132439[/import]

Maybe I need to have all my images on the root of my project for it to work? I have mine all organized e.g. (images/story1/page1/item1.png). [import]uid: 19620 topic_id: 26389 reply_id: 132442[/import]

@rxmarccall,

No, images, sound files, etc. that you include in your original build are all found in the (default) path area:
system.ResourceDirectory

However, some apps need to create files or download and store files. Because you can’t write to the system.ResourceDirectory on a device (it is read-only), you need somewhere else to put files.

* system.DocumentsDirectory - A location for persistent (saved between app runs) data.
* system.TemporaryDirectory - A place for non-persistent (may be deleted when the app closes) data.

So, the question for you that still exists is, “Why can’t you read the data from the PNG file that is under system.ResourceDirectory?”

PS - I’m going to stop responding to this thread till I get a chance to debug my (similar) problem and give some feedback on error messages, etc.

Again, thanks for the support and the lib Danny. [import]uid: 110228 topic_id: 26389 reply_id: 132446[/import]

@emaurina,
So are you getting the same error that I am getting? Or are you running into a different problem? [import]uid: 19620 topic_id: 26389 reply_id: 132483[/import]

@Danny,
I was very excited to find this library! I got it all setup and working with my app in the simulator, then I noticed that on my android device it didn’t work anymore. On my iPad it does work just fine. I ran logCat to see what the matter was and I am getting this error:

11-25 16:18:26.151 I/Corona (30377): Lua Runtime Error: lua_pcall failed with status: 2, error message is: C:\Users\rxmar_000\Desktop\BOM\scripts\pngLib.lua:34: images/story1/page1/item1.png: No such file or directory

Is it normal that it would be looking at my desktop computers directory path for files even when being run on my Android device? So the issue is its failing to find my “image” files on the Android device, any idea why this is happening? [import]uid: 19620 topic_id: 26389 reply_id: 132356[/import]

@rxmarccall,

If you resolve this, please post your resolution. I too ran into an issue on Android (Kindle Fire and Nexus 7) with pnglib. I haven’t had to debug however.

(Of course, if I get to it first, I’ll post back.) [import]uid: 110228 topic_id: 26389 reply_id: 132374[/import]

@emaurina,
glad I’m not the only one seeing this issue. I hope we can get this resolved because this library has made my app WAY more effecient in handling images. Maybe the original poster might have some ideas as well? [import]uid: 19620 topic_id: 26389 reply_id: 132378[/import]