PNG files structure - png

I've already learned how to generate BMP images based on the BMP files structure (here and here).
Now I'm looking for the PNG file structure but I haven't found any good explanations.
Do you know where I can find this explanation with schemes as well?

The complete specification is available here: http://www.libpng.org/pub/png/spec/1.2/png-1.2.pdf
Note that the PNG format is much more complex than BMP, since it allows compression, etc.

What about Wikipedia's explanation? It seems to be written very well and is very easy to understand. There's also the specification, which goes into everything.

Related

Native swift zip decompression

I would like to implement zip decompression without using external frameworks. I think that Compression framework from iOS SDK should be ok for this, but I'm not sure. I was looking for some examples on how to extract files using this but found nothing. I wan't to extract all files from zip to some directory (not Data object). Can someone help me starting this? Maybe some tutorials I haven't found? Any help will be appreciated.
zlib, which is already there, provides the raw decompression and CRC calculation engines. From there you can write your own code to interpret the zip file structure, which is documented in the PKWare appnote. It is relatively straightforward.

Matlab access PDF as an array of images

Building a system which search for a specific region in the picture, and saves it. Everything works fine. Mostly I am going to extract these regions from pdf books.
So I am looking for a solution to treat PDF file in matlab as an array of images (each page is an image). Up till now the only thing I have found is how to open pdf files in matlab.
The best solution I came up with is to export PDF as many PNG images and iterate through them. There is nothing bad with these idea, but I am wondering am I missing something
Judging from this page it appears to be impossible to import pdf directly into matlab:
And a quick file exchange search for 'pdf import' only offers an attempt to extract text, rather than the images.
So all in all your approach of saving the pdf as images and then importing them seems to be the way to go.
I agree with Salvador Dali and Dennis. To convert each page of the PDF to a png image, I downloaded imagemagick and followed the commands here:
https://aleksandarjakovljevic.com/convert-pdf-images-using-imagemagick/
Specifically:
convert -density 150 -antialias "input_file_name.pdf" -resize 1024x -quality 100 "output_file_name-%03d.png"
Of course, there are other discussion about using ImageMagick for this purpose:
Converting a PDF to PNG and
Convert PDF to PNG using ImageMagick
This is an old thread, but it's the one I found when I asked the same question, so I thought I would elaborate in case it's helpful to future users who also land on this thread.

How to create a PNG image that is only a byte

We've seen PNG images on the web that are less than 1kb. When I create a new blank PNG in Photoshop, its size is about 20-30 Kb :(
For example, I've seen a 100*10 px PNG that was only 90 bytes!
Which Apps can generate these? Do you have any tips?
After fvu's answer: plz tell me what optimizer is better than other?
There no reason a minimal png should be that big. Check out png optimizers like this one or this online tool should Photoshop not include such a tool. Google knows about even more PNG optimizer tools.
Edit: a 10*100px png floodfilled with red measures 143 bytes optimized with Paintshop Pro's integrated PNG optimizer. Apparently it can be made even smaller than what Paintshop manages :-)
Edit based on OP's comment: Corel Paint Shop Pro is a photo editor, I guess you can call it a lightweight alternative to Photoshop. It was the quickest way for me to create a png comparabable to op's example.
As for what optimizer is best: some good old fashioned testing and comparing should tell you a lot, I wouldn't be surprised to see that the performance of individual optimizers depends on the input characteristics - eg some will do better on photos than others but on computer imagery it's the other way around, based on the algorithms used.
Aside from the compression ratio the ease with which you can integrate the optimizer in your workflow should be considered quite important.

Make and edit .psd file in iPhone file system

I was wondering what the easiest way to make a .psd file from within an iPhone app. I am making an app just like the Layers app, and I can't fiure out how he makes and edits .psd files.
Writing a psd parser yourself is a futile business. See the super-famous quote from here (original source code)
// At this point, I'd like to take a moment to speak to you about the Adobe PSD format.
// PSD is not a good format. PSD is not even a bad format. Calling it such would be an
// insult to other bad formats, such as PCX or JPEG. No, PSD is an abysmal format. Having
// worked on this code for several weeks now, my hate for PSD has grown to a raging fire
// that burns with the fierce passion of a million suns.
It goes on and on. So, look for an (open-source) psd reading/writing library.
I'm the author of the Layers app the OP mentioned. Unfortunately, coneybeare is right - I pretty much wrote an objective-c implementation from scratch. The trick turned out to be basing it off a very old version of the PSD spec, from before it got insanely polluted with crap. Layers actually writes Photoshop 3 files.
UPDATE: I've published the PSDWriter from Layers on github. You can use it to write PSD files from a set of UIImages on iOS or Mac OS X: https://github.com/bengotow/PSDWriter
Enjoy!
Checkout ImageMagick. There's an iOS compiled binary that you can link into your application. Or if you want, you can set up the compilation business yourself.
They probably looked up the spec for the psd format, then figured out how to write it manually.

adding text to TIFF

I need to add text string to a TIFF image. I am planning to use libTIFF for editing the TIFF image. The plan is to convert text to image using freetype2 and then somehow render the text image on to TIFF. Is this the right approach?
Any pointers on how to convert text to image? I saw the sample code of ft2 - initialising the library, creating face and then setting character sizes. But not sure what to do next? any pointers appreaciated.
One way could be using ImageMagick. They have tools for image composition and text rendering. (and many more)
Although ImageMagick is primarily used from the command line (especially in web environments) several language interfaces are available, too. Java, C, C++, ...
ImgSource is a really nice library for C/C++ on Windows, and it can do this out of the box.
http://www.smalleranimals.com/isource.htm
It's not free, but it's pretty cheap ($59)
You don't tell us which language you need to use, should it be portable or for a given platform, etc.
Using a ready to use existing graphic library, like the (big!) ImageMagick or others like libGD or DevIL might be the easiest way, lot of them have binding for lot of languages.
if youre on windows and in c++ then it's pretty easy to use gdiplus for drawing fonts. you have access to any installed font and you can save the raster out as tiff or jpeg etc as well using the one api.
of course you could also use some combo of freetype and libtiff, but you'll have to build those libs for win32. not that its hard, just more fussing around you may not want to do.