Get image format from Scrimage Image instance - scala

I'm working with scrimage right now, and I need to get the image format from the file, as right now, if a GIF is uploaded, it will not become an animated JPEG. I need to be able to tell if the image file is a GIF so I know to not use the Format.JPEG writer. Is there any way to do this?

In release 2.0.0-M2 you can do
val format : Option[Format] = FormatDetector.detect(in)
where in is an input stream.

Related

Thumbnailator conversion from PNG to JPG results in all-white image

For many images, this code works fine to convert a PNG image to JPG:
Thumbnails.of(pngIn)
.outputFormat("jpg")
.scale(1.0)
.toFile(jpgOut);
But for this specific image:
the code results in an all-white JPG image. If someone can point me to the right way of doing things in Thumbnailator, I would very much appreciate it. Cheers!
EDIT: Well, something in the image upload / download process makes things work for the attached image! (The downloaded image is 50K while the original image is 41K, so clearly there's some funkiness going on there.) But I promise that the original PNG really does not work.
EDIT 2: This link to Google images can be used to download the 920x900 PNGWing image (41K) on the right side of the page.
The above syntax seems to be correct for converting PNG to JPG. The problem is that when the referenced image is read into a BufferedImage object, the image's type is BufferedImage.TYPE_BYTE_BINARY. While such images can be 1, 2, or 4-bit images, Thumbnailator doesn't handle 2- or 4-bit images correctly, essentially assuming that the image is a 1-bit image.
In short: the syntax is correct, but there appears to be a Thumbnailator bug that hinders successful processing of some PNG files.

Filestack - I want to convert an image to a specific pixel size before uploading it to Filestack. How can I do that?

I am working on an application for watermarking a photo. The application has three main steps: 1) upload the main image file, 2) upload the watermark image file, and 3) apply the watermark to the main photo.
I want to convert the watermark to a specific pixel size, before I upload it to Filestack to perform the watermark transformation. How can I change an image file size to specific pixel dimensions before performing the upload with Filestack?
There are a couple ways to approach this issue.
The first on would be to use the 'imageDim' function within the Filestack Filepicker.
It would look like this:
client.pick({
imageDim: [400, 400]
})
After the upload is complete you can place your watermark over the image.
If you already have the image uploaded and you want to use the existing file handle, you would do it like this:
client.storeURL('https://process.filestackapi.com/resize=height:400,width:400/'+ file.handle)
You can also add the watermark call in the storeURL function.

AlamofireImage: Is it possible to get the raw data from an NSimageview in Swift?

I am using an imagewell to accept jpg images being pasted or dragged into my OSX app. The problme is that I am struggling to get the original jpg images as OSX seems to requires me to get the Tiff version of the NSImage if I want to uplod via Alamo Fire.
Does AlamoFireImage have a fancy way of getting the original url / original raw data without converting to Tiff first?
Actually, with an NSImageWell, you don't have much possibilities regarding the dropped image. It's a convenient class for showing dropped images but as soon as you need to do more, it's not up to the task.
I suggest you use an NSImageView instead, and add drag and drop capabilities to it like in my example here: https://stackoverflow.com/a/29233824/2227743
This way you can easily get the dropped image's URL (and filename), and the image data itself of course.

Not able to read PNG format Image using Jmagick library

I am able to read JPEG format image and can write JPEG format image. I want to do same for PNG format image but i am not getting how to do that.
It's the same concept as jpeg. One of the "magicks" of the library is that it is largely type independent when writing the code. Try doing it the same way.
If you're attempting to do conversion, maybe try looking here.

How does One place an image inside of an image using metadata?

For example, I can convert the second image into NSData and then place it inside metadata inside the first image and then when I open the first image and read the metadata I can get the NSData and turn it into an UIImage.
How would I go about doing this? All the metadata tags I see are not large enough to support another picture. I know picture in picture is quite common on desktop apps so I'm interested in getting it to work on the iPhone.
Is metadata the correct way to do this or is there another way?