4

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?

Community
  • 1
  • 1
Delaney
  • 1,039
  • 1
  • 9
  • 15

2 Answers2

5

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));
}
2

There is no library out there at the moment.

I have been using ImageMagick instead. You could use Process.run() to run it. Here's an example:

Process.run('/usr/local/bin/convert', ['file', '-resize', '100x100']);
Kai Sellgren
  • 27,954
  • 10
  • 75
  • 87
  • Yeah I was hoping for a pure Dart way of doing it, most likely with headless Dartium. But this does answer the initial question. – Delaney Jun 29 '13 at 16:30
  • 1
    If something comes up, I'll update my answer. I'd also like to see a library for manipulating images. I've considered working on one, but I fear I don't have enough time for that. – Kai Sellgren Jun 29 '13 at 17:36
  • Right even though its still a valid answer looking more into doing with via ImageMagick's CLI there doesn't appear to be a way to do per pixel value reads. At that rate might as well keep my current java version and just call it directly. – Delaney Jul 01 '13 at 18:40
  • Might want to check out https://github.com/Serabe/RMagick4J/tree/master/Magick4J/src/magick4j – j_mcnally Jan 14 '14 at 03:58