Thumbnail from compressed RAW - cocoa

I need to create thumbnail images for various RAW photo files:
NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:
(id)kCFBooleanTrue,kCGImageSourceCreateThumbnailFromImageIfAbsent,
(id)[NSNumber numberWithInteger:256],kCGImageSourceThumbnailMaxPixelSize,
(id)kCFBooleanTrue,kCGImageSourceCreateThumbnailWithTransform,
nil];
thumbnail = CGImageSourceCreateThumbnailAtIndex(source,0,(CFDictionaryRef)options);
This works for image formats supported by macOS.
There are however files that macOS correctly identifies as images, but does not fully support. Typically these are the compressed variants of supported RAW formats. These share the same extension and type as the supported non-compressed variants.
For these files I would like to extract JPEG previews and thumbnails embedded in the RAW files. Basically, what I would expect from kCGImageSourceCreateThumbnailFromImageIfAbsent: Use the existing previews where available.
I have checked with exiftool. My images include both a preview and a thumbnail.
I just can't get CGImageSourceCreateThumbnailAtIndex() to use it. Is there an API or library that does extract the thumbnail even when the file format is not fully supported?

Related

Converting PDF to images of original size

I have a PDF file which is made of photographs of a book connected in a single PDF file. I'm trying to convert it back to single images in PNG format, every tool I tried asks me to set DPI which alters the size of resulting images, is there a way to get images of the exact same pixel size the original images were?
Most PDFs of books contain a single image per page and depending on the scanner these images can basically be in three different formats: JPEG, JPEG2000 or TIFF. JPEG2000 is rarely used, so your PDF probably contains JPEG and/or TIFF images.
The good thing about JPEG (and JPEG2000) images is that they can be embedded as-is into a PDF! So you can extract the images as they are stored in the PDF. With TIFF this is also sometimes possible (but I don't think always...).
As mentioned by Tim Roberts you should try using pdfimages or hexapdf images to view and extract the images stored in the PDF. This will give you the best result.

Identifying content/image type from NSImage

I have an NSImage instance and I'd like to identify the type of image it is (JPG, PNG, GIF, etc.).
Is the original format of the image preserved and possible to retrieve somehow?
EDIT:
Answers in other questions mention using CGImageSource. However, there does not seem to be a way of extracting the original data from the NSImage - only TIFFRepresentation, which will always return the TIFF image type via CGImageSource.
EDIT 2:
I think my suspicions may be true in that NSImage does not maintain the original format of the image. Everything is converted to bitmap representation. Therefore it is not possible to retrieve the original format without keeping track of it yourself. See similar answer from iOS equivalent: Detect whether an UIImage is PNG or JPEG?

Is there a generic image MIME type that modern browsers recognize?

Is there a special MIME type (e.g. application/image) that will enable the browser interpret a response as an image independent of the image type (pdf, gif, jpg)?
I have a server that automatically generates file names without extension for the uploaded images. What I want to avoid, is storing their extensions and to serve them to the clint using just the generated IDs. And I want to let the browser know it is an image, but without specifying the file extension.
No, the point of the MIME types is to identify the types of resources at the server level and allow the client to process them as is.
There are some image file types which do not have a binary signature marker (ex.: svg). Not having this marker makes the file hard to identify without a mimetype or file extension.
For example exif_imagetype is a function which identifies GIF, JPEG, PNG, SWF, PSD, BMP, TIFF_II, TIFF_MM, JPC, JP2, JPX, JB2, SWC, IFF, WBMP, XBM, ICO but does not identify SVG files.
SVG files are XML files which describe the image structure in shapes, lines and points. So it's a text file, without the full proper mime type declaring that it's not only an image but an SVG image, it couldn't be treated as an image.
<!-- how do we handle this if the server
does not give as a mime type header? -->
<img src="file.svg" />
<!-- we know it's an image but what to do
with it -->
There are cases when css or js files are being generated using php and the extension is "*.php" and the developer hasn't set the correct "text/css" or "text/javascript" header, maybe the header is "text/plain", the browser will refuse to parse & apply them.

Get EXIF information from a Quicktime Movie

For a JPG image, I can just use CGImageSourceCopyPropertiesAtIndex to obtain the various bits of EXIF information from the image. However, this API does not work with quicktime movie files.
What similar Cocoa APIs can I use to extact EXIF information from a Quicktime movie file?
EXIF is a standard for image files, not for movies. There's no EXIF information defined for movies and correspondingly there's no API to retrieve them from quicktime movie files.

If i am making a image sharing service website using the standard file upload form what images can i say it supports, other then jpg, png, gif

If i am making a image sharing service website using the standard file upload form what images can i say it supports, other then jpg, png, gif. Is there a list that shows what browsers supports what? I know that jpg png and gif are most common but what are the others. I want to be sure.
Honestly, that's pretty much all you should be concerned with. Any other file formats (like svg) are not widely supported enough.
I would suggest converting other types of files to those 3
Examples:
jpeg (simple renaming)
bmp
tiff
pcx

Resources