Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you load an Image server side in dart?

Tags:

dart

I've seen the answers for using an ImageElement to load an image. This only works on the browser side and I wanted to do some processing on the server.

Is there any way to load and read RGBA values from a PNG in server side dart? If not are there any server side image processing libraries planned?

Is there anyway to run Dartium "headless" so I can use the canvas api to do what I want?

like image 717
Delaney Avatar asked Mar 23 '23 10:03

Delaney


1 Answers

There is a dart library that can read and write PNG images server side, http://pub.dartlang.org/packages/image

The library can read and write PNG and JPG images, and provides a number of image manipulation commands.

For example, to read a PNG, resize it, and save it to disk using this library:

import 'dart:io' as Io;
import 'package:image/image.dart';
void main() {
    // Read a PNG image from file.
    Image image = readPng(new Io.File('foo.png').readAsBytesSync());

    // Resize the image to a 120x? thumbnail (maintaining the aspect ratio).
    Image thumbnail = copyResize(image, 120);

    // Save the thumbnail to disk as a PNG.
    new Io.File('foo-thumbnail.png').writeAsBytesSync(writePng(thumbnail));
}
like image 120
Brendan Duncan Avatar answered Apr 02 '23 17:04

Brendan Duncan