base64 to Blob removing the metadata available with the image - image

I am using below method to convert base64 to blob:
var blobData = new Blob([base64Str], {type: 'image/png'});
Now once the image file is created using this Blob:
var imageData = new FormData();
var counter = 1;
imageData.append("file", blobData, 'file1.png');
I do not see the metadata. Is there a way to add the metadata being stripped off the image file?
I download the image file created above and view it in http://metapicz.com/#landing
When viewing original image it shows the location info and other metadata, but when viewing the downloaded image it does not show any metadata.

Figured it out myself, the datatype returned from iOS native (swift) is UIImage which removed the EXIF information and only returns base64 of image data.
Changed the code to return entire image data + metadata at iOS native side.

Related

Not able to display blob as image in flutter

I'm trying to display an image stored as blob in flutter. I'm using a PHP API to get the image and send it as a base64 string. When the image builds, there is an error that says Failed decoding image. Data is either invalid, or it is encoded using an unsupported format.
Running an xampp server. PHP APIs. Flutter application run using android studio emulator
I am able to display the image on a webpage using a HTML img tag.
Image.memory(base64Decode(imagebase64string));
I expect the image to be shown on the screen
Error says
Failed decoding image. Data is either invalid, or it is encoded using an unsupported format.
You have to remove base64 header manualy:
final stripped =
imagebase64string.replaceFirst(RegExp(r'data:image/[^;]+;base64,'), '');
setState((){
data = base64.decode(stripped);
});
Then you can use data with Image.memory.
Image.memory(data)
Decode it back to a byte array from base64 and use this from dart.ui:
final codec = await ui.instantiateImageCodec(data);
final frame = await codec.getNextFrame();
return frame.image;
Or even simpler, from package:flutter/widgets.dart:
return decodeImageFromList(data);

Native script - Convert base64 string to image and store it in local file system

In my requirement, we need to take digital signature. Digital signature we are receiving it as base 64 string.
Is any way to convert base64 to image in native script.
Official NativeScript Docs for the image-source module have the following
let img: imageSource.ImageSource;
img = imageSource.fromBase64(jpgImageAsBase64String);
Which loads the image in memory from the string. Following you can save the image calling the saveToFile method of image-source instances
let saved = imageSource.saveToFile(path, "png");
if (saved) {
console.log("Image saved successfully!");
}

Storing and removing images from core data

I have an image, and I am storing it in the core data (its a very small image, and I'm using external storage).
Code to convert to data is:
imageData = NSData(data: UIImageJPEGRepresentation(profilePic.backgroundImage(for: UIControlState.normal)!, 0.5)!)
then for debugging purposes I am trying to convert straight back into an image:
let image = imageData
let secondimage = UIImage(data: image as Data, scale: 0.5)
profilePic.setBackgroundImage(secondimage, for: UIControlState.normal)
However, when it converts back and displays the results of the conversion, the image is gone and it displays nothing, but gives no error.
Where am I going wrong to convert back to the image?

App engine image service throws exception with jpeg output image

I am getting an ImagesServiceFailureException exception from the app engine ImagesServiceFactory when specifying JPEG as the output format. It works fine when I specify PNG as the output format. I have only tried this on the app engine development server, not yet on the production server. JPEG is supposed to work according to the app engine docs.
Any idea why this doesn't work? I really don't want to use PNG because of the much greater size images relative to JPEG.
Following is my code:
byte[] sourceData = fetchBlobData(sourceKey);
Image sourceImage = ImagesServiceFactory.makeImage(sourceData);
// Image sourceImage = ImagesServiceFactory.makeImageFromBlob(thumbSourceKey);
ImagesService imagesService = ImagesServiceFactory.getImagesService();
// Create the transform and the new image
Transform resize = ImagesServiceFactory.makeResize(NEW_WIDTH,NEW_HEIGHT);
Image newImage = imagesService.applyTransform(resize, sourceImage, OutputEncoding.JPEG);
When I output as JPEG, I get the following exception:
com.google.appengine.api.images.ImagesServiceFailureException: Failed to encode image
Any help would be greatly appreciated.

Creating and serving an image using AppEngine

In Google AppEngine I want to transform a boolean[] into an image then serve the image. I want the boolean[] to be transformed to black and white pixels. I can see that AppEngine provides
import com.google.appengine.api.images.Image;
import com.google.appengine.api.images.ImagesService;
import com.google.appengine.api.images.ImagesServiceFactory;
// ...
byte[] imageData; // ...
ImagesService imagesService = ImagesServiceFactory.getImagesService();
Image image = ImagesServiceFactory.makeImage(imageData);
but I don't know what the format of the byte[] imageData should be, i.e., how to transform the boolean[] to byte[]
And once I have this image, how can the client get it?
The Image service API accepts data in any of the supported image file formats. According to this page, these formats include "JPEG, PNG, WEBP, GIF (including animated GIF), BMP, TIFF and ICO". The Image service does not provide a way to create new image data from scratch. But you can use a graphics library to produce the image in one of the accepted data formats, then use the service to convert it to another format, or transform it. Of course, depending on the graphics library, you may be able to get the final image directly from the library, and not use the service.
To serve an image, just set the appropriate Content-Type header for the data format you're using, then write the bytes of the image data to the response's output stream:
// byte[] pngData = ...
resp.addHeader("Content-Type", "image/png");
resp.getOutputStream().write(pngData);
If you want to try generating the image data without a library, the BMP format might be easiest. You can use the Images service to convert this to PNG.

Resources