Magick++: how do i use magick++ to convert an animated gif to an animated webp? - imagemagick

The main logic code is as follows:
std::vector<Magick::Image> images;
Magick::readImages(&images, input_blob);
for (auto &image : images) {
image.magick("WEBP");
}
output_blob = new Magick::Blob;
Magick::writeImages(images.begin(), images.end(), output_blob);
When i wrote output_blob data into a file, i got a static webp image.
Q: How can i get an animated webp file?
Thanks in advance!

Related

Is it possible to apply Image processing Filters on raw SVG image for editing apps in iOS?

Image or color properties filter like contrast, exposure, vibrance, tint etc can be achieved well in raster image using CIFilter or GPUImage Filter in iOS.
Is there any way out to apply those basic filters in SVG image ?
I can saturate, brighten the SVG using the Color class of Macaw library this way...
let shape = svgContent as? Shape {
if let shapeOriginalColor = allNodeColors[shape.id] as? Color {
let shiftedColor = shapeOriginalColor.colorToUIColor().saturated(amount: saturation).lighter(amount: brightness)
shape.fill = Color.convert(from: shiftedColor)
}
but seems like others filter can’t be achieved as there is no prominent support for SVG in iOS !

How to convert a PNG to a WebP in Swift?

I'm trying to convert a PNG image in Webp in Swift, the only framework I got working is OpenCV through Objective-c++. The problem is that if I resize the image by 512x512 (that's the resolution I need) it crashes:
If I resize the image (either with OpenCV either with Swift) to another resolution (ex 510x510) it doesn't crash.
The strange thing is that on the simulator it never crashes while on the iPhone XS it crashes 90% of the times. How can I convert a PNG to a Webp in Swift? Why is OpenCV crashing on the imwrite instruction if the Mat is 512x512?
UPDATE:
OpenCV version: 3.4.2
I found out that this problem happens when the PNG image get processed before from the Core Graphics framework. I need to use it since I save a UIVIew as UIImage this way:
let renderer = UIGraphicsImageRenderer(bounds: bounds)
return renderer.image { rendererContext in
layer.render(in: rendererContext.cgContext)
}
Swift 4.0
pod both 'SDWebImage' ( https://github.com/SDWebImage/SDWebImage ) AND 'SDWebImage/WebP' ( https://github.com/SDWebImage/SDWebImageWebPCoder )
import SDWebImage
if let image_download = UIImage(data: data) {
let photo:Data = image_download.sd_imageData(as: SDImageFormat.webP)!
}
I ended up using another framework to convert PNG to WebP: https://github.com/seanooi/iOS-WebP, had to create the wrapper to use it on swift but it works very good 😊
My wrapper is very simple but does what I needed:
#import <Foundation/Foundation.h>
#import "WebPWrapper.h"
#import "UIImage+WebP.h"
#implementation WebPWrapper
-(NSData *)convertUIImageToWebp:(UIImage *)image :(int)quality {
NSData *webPData = [UIImage imageToWebP:image quality:quality];
return webPData;
}
#end
In swift I use it this way:
let webPData = WebPWrapper().convertUIImage(toWebp: image, 90)

Manipulating .gif animation with wand

I'm working with wand to basically do a frame-by-frame translation of a gif. I want to transpose an image into each frame of a gif, then save the output animated gif.
def placeImage(gif_name, image_name, save_location):
with Image(filename = gif_name) as gif:
with Image(filename = image_name) as image:
new_frames = []
for frame_orig in gif_new.sequence:
frame = frame_orig.clone()
with Drawing() as draw:
draw.composite(operator='src_over', left=20, top=20,
width=image.width, height=image.height, image=image)
draw(frame)
new_frames.append(frame)
So now I've got all of these frames (though they're not SingleImage objects, but Image objects) that I'd like to put back together and generate a new gif. Any advice?
I'd like to be able to do something like:
with gif.clone() as output:
output.sequence=new_frames
output.save(filename=save_location)
I just answered something very similar here: Resizing GIFs with Wand + ImageMagick
with Image() as dst_image:
with Image(filename=src_path) as src_image:
for frame in src_image.sequence:
frame.resize(x, y)
dst_image.sequence.append(frame)
dst_image.save(filename=dst_path)
Hope that helps!

Write UIImage to PNG; read PNG into UIImage; resulting image has twice the resolution

Following these steps I'm getting an unexpected result:
1) Write UIImage to PNG
2) Read PNG into UIImage
Result: the sizes of the UIImages (before and after PNG) are different. The UIImage created by reading from the PNG has twice the resolution as the original UIImage used to create the PNG.
Swift pseudocode follows:
var initialImage : UIImage;
// Obtain UIImage from UIImagePickerController, Images.xcassets, ...
// As an example, consider a UIImage with size = (420.0, 280.0).
println("Image size = \(initialImage.size)") // Indicates "Image size = (420.0, 280.0)"
// Write image to file
UIImagePNGRepresentation(myImage).writeToFile(imagePath, atomically: true)
// Retrieve image from file
let newImage = UIImage(contentsOfFile: imagePath)!
println("Image size = \(initialImage.size)") // Indicates "Image size = (840.0, 560.0)"!
All is well otherwise. Displaying the newly read image works great.
I'm running this connected to an iPhone 6. Any thoughts would be greatly appreciated.
gary
It's converting it for the retina display. Each point is represented by 2 pixels on the screen so the saved image is double the resolution. This is a good article to reference: http://www.paintcodeapp.com/news/iphone-6-screens-demystified

trying to load a bitmap, but xna want´s a Texture2D

I'm currently trying to load a simple bitmap using XNA but I get the following error:
Error loading "Maps\standard". File contains Microsoft.Xna.Framework.Graphics.Texture2D but trying to load as System.Drawing.Bitmap.
code:
public Bitmap map;
public void load(Game game, String image) {
path = image; //path to image
map = game.Content.Load<Bitmap>("Maps/"+path);
sizeX = map.Width;
sizeY = map.Height;
}
You want the below:
map = game.Content.Load<Texture2D>("Maps/"+path);
The way XNA works is that there is a content pipeline, which takes inputs (like your bitmap image) and produces outputs (the Texture2D), which is in a different format to the input.
XNA works with a Texture2D object when displaying images.
Now, I just use the C# standard
Bitmap bmp = (Bitmap)Bitmap.FromFile(path);

Resources