GithubHelp home page GithubHelp logo

brendan-duncan / image Goto Github PK

View Code? Open in Web Editor NEW
1.1K 22.0 245.0 56.69 MB

Dart Image Library for opening, manipulating, and saving various different image file formats.

License: MIT License

Dart 99.37% HTML 0.13% CSS 0.48% Batchfile 0.02%
dartlang image image-processing jpeg png webp dart dart-library dart-package dart-web

image's Introduction

Dart Image Library

Dart CI pub package

Overview

The Dart Image Library provides the ability to load, save, and manipulate images in a variety of image file formats.

The library can be used with both dart:io and dart:html, for command-line, Flutter, and web applications.

NOTE: 4.0 is a major revision from the previous version of the library.

Read/Write

  • JPG
  • PNG / Animated APNG
  • GIF / Animated GIF
  • BMP
  • TIFF
  • TGA
  • PVR
  • ICO

Read Only

  • WebP / Animated WebP
  • PSD
  • EXR
  • PNM (PBM, PGM, PPM)

Write Only

  • CUR

Examples

Create an image, set pixel values, save it to a PNG.

import 'dart:io';
import 'package:image/image.dart' as img;
void main() async {
  // Create a 256x256 8-bit (default) rgb (default) image.
  final image = img.Image(width: 256, height: 256);
  // Iterate over its pixels
  for (var pixel in image) {
    // Set the pixels red value to its x position value, creating a gradient.
    pixel..r = pixel.x
    // Set the pixels green value to its y position value.
    ..g = pixel.y;
  }
  // Encode the resulting image to the PNG image format.
  final png = img.encodePng(image);
  // Write the PNG formatted data to a file.
  await File('image.png').writeAsBytes(png);
}

To asynchronously load an image file, resize it, and save it as a thumbnail:

import 'package:image/image.dart' as img;

void main(List<String> args) async {
  final path = args.isNotEmpty ? args[0] : 'test.png';
  final cmd = img.Command()
    // Decode the image file at the given path
    ..decodeImageFile(path)
    // Resize the image to a width of 64 pixels and a height that maintains the aspect ratio of the original. 
    ..copyResize(width: 64)
    // Write the image to a PNG file (determined by the suffix of the file path). 
    ..writeToFile('thumbnail.png');
  // On platforms that support Isolates, execute the image commands asynchronously on an isolate thread.
  // Otherwise, the commands will be executed synchronously.
  await cmd.executeThread();
}

image's People

Contributors

a-siva avatar adil192 avatar annorax avatar brendan-duncan avatar brendan-duncan-g avatar creativecreatorormaybenot avatar davidmorgan avatar dnfield avatar fox32 avatar gmilou avatar gmpassos avatar hpoul avatar jdeltoft avatar jfoutts avatar karavindhan avatar kevmoo avatar kinha08 avatar lasserosenow avatar lrhn avatar marcjoha avatar mightystud avatar niwatly avatar refotografia avatar ruskakimov avatar ryankauk avatar simonit avatar tgucio avatar tmaiaroto avatar tvolkert avatar wcfv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

image's Issues

Progress event?

Hi, encoding/decoding images takes a little while (especially on mobile devices). It would be nice to have an optional progress event after each line or so of encoding/decoding. Possible?

AxisAligned DrawLine bug

I noticed that drawing lines "backwards" wouldn't render. The bug is located in draw_line.dart:

  // Axis-aligned lines
  if (dx == 0) {
    for (int y = y1; y <= y2; ++y) {          <-- error here. Not checking for dy >= 0
      drawPixel(image, x1, y, color);
    }
    return image;
  } else if (dy == 0) {
    for (int x = x1; x <= x2; ++x) {          <-- error here too. Need check for dx >= 0
      drawPixel(image, x, y1, color);
    }
    return image;
  }

A quick fix is to check for dy >= 0 and flip from

    // Axis-aligned lines
    if (dx == 0) {
      if (dy >= 0)
        for (int y = y1; y <= y2; ++y) {
          Im.drawPixel(image, x1, y, color);
        }
      else
        for (int y = y2; y <= y1; ++y) {                      <-- y1 and y2 flipped
          Im.drawPixel(image, x1, y, color);
        }
      return image;
    } else if (dy == 0) {
      if (dx >= 0)
        for (int x = x1; x <= x2; ++x) {
          Im.drawPixel(image, x, y1, color);
        }
      else
        for (int x = x2; x <= x1; ++x) {                    <-- x1 and x2 flipped
          Im.drawPixel(image, x, y1, color);
        }
      return image;
    }

performance seems to be low

I'm trying to stream images from my websocket server to webbrowser.

the server is written in c++ with libwebp to compress images into webp format.

the web browser side is written in dart with this image package. I realized that decoding a small image 300*450 needs 350msecs, this seems to be too much for a streaming program :(

rendering also takes long time, 60msecs, with the method you showed in the document:

var imageData = canvas.context2D.createImageData(image.width, image.height);
  imageData.data.setAll(0, image.getBytes());
  canvas.context2D.putImageData(imageData, 0, 0,0,0,image.width,image.height); 

here are some detailed numbers (unit msec):
run as javascript:
time, network:1 decode: 352 render: 58

run as dart:
time, network:2 decode: 224 render: 60

Support for image diffing?

I've ported https://github.com/mapbox/pixelmatch to Dart (which is fairly trivial) to help with detecting differences between images. My goal is to incorporate this into some rendering tests I have to check for fidelity between a known good render and the latest output.

I think it could make sense to incorporate the logic into this package, perhaps as a dependency or perhaps as its own class/module. What do you think?

A primary goal I have is to eventually write a matcher that can use it to report on how many pixels are different in a test/expect and perhaps optionally output the difference image for reference.

Here's the basic idea of what it can do:

image

PNG: Gamma chunk incorrectly applied to ALPHA

According to specs:
The gamma value has no effect on alpha samples, which are always a linear fraction of full opacity

Setup: Image input: PNG Grayscale+Alpha (2byte). Random gamma chunk of 0.45. Alpha channel is initially 192 (0xC0) and is changed to 224 (0xE0) due to gamma/clut tables.

Error in pubspec.yml

Saw you just updated this, not sure if you caught this or if you are even experiencing this:

"transformers.$dart2js" refers to a package that's not listed in "dependencies".

Jpg encode lower quality value results in odd colors

Could this be related to those shift operators again? If I set quality to anything but the default 100, it produces results with bright pink and green pixels scattered all over, like so:

quality-65-issue

quality-65-zoom

In this example, the quality was set to 65.

Tiff decode issue

Hello,

We faced with issue of decoding some tiff images.
For most tiffs it works fine, but for some we have next result (see attach).

Can you please share your thoughts on this? Thank you!

Image with issue
localhost_63342_dart-imaging_web_tools_tests html chromium 2016-05-19 18 10 23

original image

tmb9.tig.tiff.zip

How to load 16bit Grayscale TIFF images?

Hi Brendan:

We're trying to use this package to load some 16bit Grayscale TIFF images and display them. Using Image.dart, we can load and display RGB TIFF images (2.TIF) correctly, but we couldn't seem to load and display 16 Grayscale TIFF images (1.TIF) correctly. I'm including a couple of such TIFF images here:

https://drive.google.com/file/d/0B_y0G33KtOykcGdPcERmNThrQWc/view?usp=sharing

Could you check them out and show us how to load and display them correctly?

Thank you.

Question about performance

I am thinking to use the image library for my game framework. I do like the fact that your library allows for image editing on the go.

Question is, do you think the library is a good fit for a game framework performance-wise? (I haven't taken a dive into your lib's code).

copyResize should respect EXIF rotation

I'm using this in a Flutter project to upload photos from a phone to cloud storage, and to reduce file size and costs I'm using copyResize to first scale down the image. If the picture was taken in portrait, the photo is left in horizontal orientation and the EXIF data is not copied, so the final receiver of the photo just sees it as a standard horizontal photo.

The two obvious solutions I can think of are to either forward on the original EXIF data or to use the orientation data to first copyRotate before the resize.

(PS. I love this library. It "just works." I haven't had to think much about it until this point. Thanks for your work on it.)

PSD format support

Most of our asset source files are Photoshop files. It would be really cool to have the ability to convert them to png files using a pub transformer during build. For that PSD format support would be cool (read only?). I'm not sure about the complexity and documentation of the format, so maybe it is imposible. At the moment we plan to use ImageMagick as a format conversation tool. But with support in this library we could do it in Dart out of the box.

Dart 2 runtime failures in test

dart --preview-dart-2 test/filter_test.dart

type 'int' is not a subtype of type 'double' where...
type 'int' is not a subtype of type 'double' where
int is from dart:core
double is from dart:core
../..image/lib/src/filter/smooth.dart 12:10 smooth

Convert shift operators

So I discovered after building and running dart2js...The JavaScript wasn't coloring the images properly. A co-worker and I sat down today and traced things back and finally discovered it wasn't in the encoding or base64 or anything like that, it was in the reading of the data. There are shift operators being used and JavaScript has a problem with them in some cases. I found this: http://stackoverflow.com/questions/15457893/java-right-shift-on-negative-number/15457908#15457908 ...but that's for Java. It's different in JavaScript, but I think similar.

What we ended up doing was doing the math, pow(2, ShiftAmount) and dividing or multiplying depending on the shift direction. In the case of division, we also rounded the values so there were no problems there.

...and...It worked! I was missing a few replacements and kept testing and each time I tested I could see the image sorta materialize =) Was kinda fun. Once I found all the places it was being used and replaced things, the image looked perfect.

...For JPG. I'm assuming there's other areas in the package that use the shift operators and I'll try to run through them and replace them. I also want to see if I can optimize some of the math a bit so that the operations aren't more expensive than need be. The shift operators would be ideal, but I'm not sure they can be used if you plan to convert down to JavaScript using dart2js.

I absolutely will get to these, so I can submit a pull request if you like. Though I was interested in getting your thoughts (maybe you know of a better solution).

the decodeImage() seems crashed when use in Flutter , call help!!

my code :

--- image: "^1.1.30"

  import 'dart:io' as Io;
  import 'package:image_picker/image_picker.dart';

  Io.File imgFile = await ImagePicker.pickImage(source: ImageSource.gallery);
  imageFun.Image image = imageFun.decodeImage(imgFile.readAsBytesSync());   // crash here..

---- error

[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
type 'List' is not a subtype of type 'List' where
List is from dart:core
List is from dart:core
Int16List is from dart:typed_data

#0 JpegData._readFrame (file:///Users/chaim/.pub-cache/hosted/pub.flutter-io.cn/image-1.1.30/lib/src/formats/jpeg/jpeg_data.dart:493:35)
#1 JpegData._read (file:///Users/chaim/.pub-cache/hosted/pub.flutter-io.cn/image-1.1.30/lib/src/formats/jpeg/jpeg_data.dart:313:11)
#2 JpegData.read (file:///Users/chaim/.pub-cache/hosted/pub.flutter-io.cn/image-1.1.30/lib/src/formats/jpeg/jpeg_data.dart:94:5)
#3 JpegDecoder.decodeImage (file:///Users/chaim/.pub-cache/hosted/pub.flutter-io.cn/image-1.1.30/lib/src/formats/jpeg_decoder.dart:46:10)
#4 decodeImage (file:///Users/chaim/.pub-cache/hosted/pub.flutter-io.cn/image-1.1.30/lib/src/formats/formats.dart:60:18)

chaimdeiMac-2:Application chaim$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, v0.2.5-pre.39, on Mac OS X 10.13.2 17C205, locale zh-Hans-US)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 9.3)
[✓] Android Studio (version 3.1)
[✓] VS Code (version 1.22.0)
[✓] Connected devices (1 available)

Got "RangeError (index): Index out of range"

Hi,

i don't know why, but your demo-code fires this error. The lib is already stable?
[103255 is the length of the test file]

RangeError (index): Index out of range: index should be less than 103255: 103255
#0      Uint8List.[] (dart:typed_data-patch/typed_data.dart:981)
#1      InputBuffer.readByte (package:image/src/util/input_buffer.dart:137:18)
#2      JpegData._nextMarker (package:image/src/formats/jpeg/jpeg_data.dart:389:19)
#3      JpegData.validate (package:image/src/formats/jpeg/jpeg_data.dart:19:18)
#4      JpegDecoder.isValidFile (package:image/src/formats/jpeg_decoder.dart:15:27)
#5      findDecoderForData (package:image/src/formats/formats.dart:14:11)
#6      decodeImage (package:image/src/formats/formats.dart:56:21)
Dart VM version: 1.13.0-dev.2.0 (Tue Sep 08 05:25:02 2015) on "windows_x64"

decodeImage is slow on iOS with large images (Flutter)

Hey there,

I just implemented your image library with flutter and we are noticing very slow decoding on iOS.

This is my compression function:

  static Future<File> compressImageFile(File inputFile,
      {int resizePercentage = 50, int quality = 90}) async {
    List<int> bytes = await inputFile.readAsBytes();

    Image image = decodeImage(bytes);

    if (image.height > 1500 || image.width > 1500) {
      print("Resize required");
      print("Image size before: ${image.height}x${image.width}");
      var newWidth = (image.width / 100 * resizePercentage).toInt();
      var newHeight = (image.height / 100 * resizePercentage).toInt();

      Image resizedImage = copyResize(image, newWidth, newHeight);

      print("Image size after: ${resizedImage.height}x${resizedImage.width}");

      String originalFileName = basename(inputFile.path);
      String filePath = inputFile.parent.path;
      String newFile =
          join(filePath, originalFileName.split('.').first + "_compressed.jpg");

      File outputFile = new File(newFile);
      outputFile.writeAsBytesSync(encodeJpg(resizedImage, quality: quality),
          mode: FileMode.WRITE, flush: true);

      return outputFile;
    }

    return inputFile;
  }

This is the sample image we tried on both Android & iOS. Android takes around 5 seconds for the function to run (most time in "decodeImage") and the app crashed after a few minutes waiting for decodeImage on iOS.

https://www.pexels.com/photo/1-wtc-america-architecture-buildings-374710/

double is not an int error

Heya. While trying to load up a particular image, it shows this error:

2014-07-06 19:12:06.147: SEVERE: (FilesResource) type 'double' is not a subtype of type 'int' of 'index'.
2014-07-06 19:12:06.147: SEVERE: (FilesResource) #0      List.[] (dart:core-patch/array.dart:12)
#1      JpegData.getData (package:image/src/formats/jpeg/jpeg_data.dart:231:47)
#2      JpegDecoder._copyToImage (package:image/src/formats/jpeg_decoder.dart:78:34)
#3      JpegDecoder.decodeImage (package:image/src/formats/jpeg_decoder.dart:56:17)
#4      decodeImage (package:image/src/formats/formats.dart:60:29)
#5      Thumbnailer.createThumbnailForBits (package:dartlery_server/src/thumbnailer.dart:14:49)
#6      FilesModel.createFile.<anonymous closure>.<anonymous closure> (package:dartlery_server/model/files_model.dart:113:43)
#7      _rootRunUnary (dart:async/zone.dart:730)
#8      _RootZone.runUnary (dart:async/zone.dart:864)
#9      _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:488)
#10     _Future._propagateToListeners (dart:async/future_impl.dart:571)
#11     _Future._complete (dart:async/future_impl.dart:317)
#12     Stream.forEach.<anonymous closure> (dart:async/stream.dart:623)
#13     _rootRun (dart:async/zone.dart:719)
#14     _RootZone.run (dart:async/zone.dart:862)
#15     _BaseZone.runGuarded (dart:async/zone.dart:574)
#16     _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:385)
#17     _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:394)
#18     _BufferingStreamSubscription._close (dart:async/stream_impl.dart:283)
#19     _SinkTransformerStreamSubscription._close (dart:async/stream_transformers.dart:92)
#20     _EventSinkWrapper.close (dart:async/stream_transformers.dart:18)
#21     _ResultsImpl._ResultsImpl.<anonymous closure> (package:sqljocky/src/results/results_impl.dart:15:19)
#22     _HandlerEventSink.close (dart:async/stream_transformers.dart:219)
#23     _handleDone (dart:async/stream_transformers.dart:137)
#24     _rootRun (dart:async/zone.dart:719)
#25     _RootZone.run (dart:async/zone.dart:862)
#26     _BaseZone.runGuarded (dart:async/zone.dart:574)
#27     _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:385)
#28     _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:394)
#29     _DelayedDone.perform (dart:async/stream_impl.dart:604)
#30     _StreamImplEvents.handleNext (dart:async/stream_impl.dart:701)
#31     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:661)
#32     _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:23)
#33     _asyncRunCallback (dart:async/schedule_microtask.dart:32)
#34     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:128)

Adding GPU textureformats

Not sure this fits this library but:
Support various GPU texture formats would be helpful for WebGL applications.
ETC, PVRTC, S3TC/DXTC and maybe crunch.
Not sure if its possible to write compression/decompression for all these formats in dart because some of them may have no public spec.
Maybe it is easier to use binaries here.

Add trimTransparent

Would be great to have ability to trim the transparent pixels. Should probably be an async callback that gives info like the offset X,Y of the NW point where the crop occurred and the resulting image.

Interpolation quality

I don't know if I'm doing it wrong, but I'm trying to create thumbnails. This is my code.

if(source_image.width==source_image.height) {
  new_height = SettingsModel.thumbnailMaxDimension;
  new_width = SettingsModel.thumbnailMaxDimension;
} else if(source_image.width>=source_image.height) {
  new_height = -1; // The image library has it's own internal auto-resize that mantains aspect ratio
  new_width = SettingsModel.thumbnailMaxDimension;
} else {
  new_height = SettingsModel.thumbnailMaxDimension;
  double ratio = source_image.width / source_image.height;
  new_width = (SettingsModel.thumbnailMaxDimension * ratio).round();
}

thumbnail = image.copyResize(source_image,new_width,new_height,image.CUBIC);

But the resized images come back looking like this (included a shot from doing a cubic resize in GIMP for comparison):

resize comparison

Am I not calling the CUBIC interpolation properly, or is this just how cubic is in this lib? I'm using version 1.1.21.

Transparent issue

I'm using my image_transformer package (https://github.com/Fox32/image_transformer) to convert a psd file to png. But I noticed some strage behavior for the following PSD file:

https://dl.dropboxusercontent.com/u/480043/grass_01_02.psd

If I use Photoshop to export the image (with export for web) I get the following file;

grass_01_02_photoshop

But using the transformer I get:
grass_01_02_wrong

You might not see a difference on the embedded images here, but they look different on a black background, see the white border:

black

I'm not sure if the problem is caused by the PSD decoder or the PNG encoder.
Thanks for your great support for this package!

openexr decoder

I am already working on this; adding the issue to track it.
It will support decoding to HDR images, and tone-mapping operations to convert to a regular image.

Error reading a png file (jpeg validate range error)

Calling decodeImage in a loop of images, all in PNG format.

Stack:

Unhandled exception:
Uncaught Error: RangeError: 355 must be in the range [0..355)
Stack Trace:
#0      _throwRangeError (dart:typed_data-patch/typed_data.dart:3571)
#1      Uint8List.[] (dart:typed_data-patch/typed_data.dart:790)
#2      InputBuffer.readByte (package:image/src/util/input_buffer.dart:137:18)
#3      JpegData._nextMarker (package:image/src/formats/jpeg/jpeg_data.dart:389:27)
#4      JpegData.validate (package:image/src/formats/jpeg/jpeg_data.dart:19:29)
#5      JpegDecoder.isValidFile (package:image/src/formats/jpeg_decoder.dart:15:35)
#6      findDecoderForData (package:image/src/formats/formats.dart:14:22)
#7      decodeImage (package:image/src/formats/formats.dart:56:39)

The png file is 355 bytes (19x80 pixel left arrow sprite).

Png decoder issue

Hello,
When I decode an re-encode this 8-bit color png image (encoded with imagemagick). I get a weird result.

Before:
icon

After:
icon_black_after

Image icon = decodePng(new File('icon.png').readAsBytesSync());
new File('icon_after.png').writeAsBytesSync(encodePng(icon));

JPEG decoding error

RangeError (index): Invalid value: Not in range 0..112, inclusive: 113
#0 List.[] (dart:core-patch/array.dart:9)
#1 JpegScan._decodeMcu (package:image/src/formats/jpeg/jpeg_scan.dart:298:41)
#2 JpegScan.decode (package:image/src/formats/jpeg/jpeg_scan.dart:89:17)
#3 JpegData._readSOS (package:image/src/formats/jpeg/jpeg_data.dart:568:55)
#4 JpegData._read (package:image/src/formats/jpeg/jpeg_data.dart:338:11)
#5 JpegData.read (package:image/src/formats/jpeg/jpeg_data.dart:94:5)
#6 JpegDecoder.decodeImage (package:image/src/formats/jpeg_decoder.dart:46:10)
#7 decodeImage (package:image/src/formats/formats.dart:60:18)

Image: https://rand.darkholme.net/_images/5c0c01f531a6a7b08c83cf021faed25d/

Error while decoding large (>4MB) image List<int>

So, after loading a file into a List I try to create an image with this command:

image.Image source_image = image.decodeImage(data);

I end up getting this error:

RangeError: 4792720 must be in the range [0..4765668)
#0 _throwRangeError (dart:typed_data-patch/typed_data.dart:3638)
#1 Uint8List.
#2 InputBuffer.readByte (package:image/src/util/input_buffer.dart:137:18)
#3 JpegData._nextMarker (package:image/src/formats/jpeg/jpeg_data.dart:369:27)
#4 JpegData.validate (package:image/src/formats/jpeg/jpeg_data.dart:41:27)
#5 JpegDecoder.isValidFile (package:image/src/formats/jpeg_decoder.dart:15:35)
#6 findDecoderForData (package:image/src/formats/formats.dart:14:22)
#7 decodeImage (package:image/src/formats/formats.dart:56:39)
#8 Thumbnailer.createThumbnailForBits (package:dartlery_server/src/thumbnailer.dart:10:49)
#9 FilesModel.createFile.

4765668 is the size of the file in question here, so it seems like there's some kind of miscalculation going on here. Here's the image:

2318

Can't loop gif

I can't seem to figure out how to loop my gif. The default loopCount is already zero (forever) and i tried changing it but it doesn't seem to have any effect. Am i doing something wrong here?

The backgroundColor property doesn't seem to do anything either but i can get around that.

main() async {

  var fontFile = await new File('font.zip').readAsBytes();

  var font = readFontZip(fontFile);

  Animation anim = new Animation();

  // anim.loopCount = 0;

  String str = 'Animation';

  for (var i = 0; i < 10; i++) {

      Image image = new Image(480, 120);

      for (var i = 0; i < str.length; i++) {
        // slightly modified drawChar()
        drawCharacter(image, font, 64*i, 0, str[i], i);
      }

      anim.addFrame(image);

  }

  List<int> gif = encodeGifAnimation(anim);

  new File('test.gif')
        ..writeAsBytesSync(gif);

}

Tag releases

Hi there, could you please tag your releases with the version number so pub can figure out versions?

ImageException: Invalid IDAT checksum

I got this exception at one point. I restarted my Dart server and tried again, and it worked, but figured I'd bring it up as it may be something I shouldn't ignore.

ImageException: Invalid IDAT checksum

#0      PngDecoder.decodeFrame (package:image/src/formats/png_decoder.dart:215:11)
#1      PngDecoder.decodeImage (package:image/src/formats/png_decoder.dart:304:12)
#2      decodeImage (package:image/src/formats/formats.dart:60:18)
#3      ImageUtil.resize.<resize_async_body> (package:woven/src/server/util/image_util.dart:19:19)
...

Thank you for a great lib! I had been using ImageMagick via Dart for a long time. Recently I switched to your lib and I was so happy to kill the IM dependency.

Question: Get Pixel

I have been unable to compare the colors of the getPixel method successfully to some hex numbers constants I defined.

The source is a standard PNG image without transparency.
I have just been getting false results doing the following:

const int RED = 0xff0000

int pixel = image.getPixel(5,5);

if ( (pixel >> 8).toUnsigned(32) == RED){
   print ('RED PIXEL');
}

However, even black dots are printing RED PIXEL in the console with this approach.

Am I doing it the wrong way?

RangeError

I get this error with a few images (very few out of thousands, but it keeps coming up), none of which appear to have any issues when opened in other applications: It occurs when I try to read the file.

RangeError (index): Invalid value: Only valid value is 0: 1
#0      List.[] (dart:core-patch/growable_array.dart:151)
#1      JpegScan._decodeHuffman (package:image/src/formats/jpeg/jpeg_scan.dart:134:18)
#2      JpegScan._decodeACSuccessive (package:image/src/formats/jpeg/jpeg_scan.dart:238:20)
#3      JpegScan._decodeBlock (package:image/src/formats/jpeg/jpeg_scan.dart:308:13)
#4      JpegScan.decode (package:image/src/formats/jpeg/jpeg_scan.dart:78:11)
#5      JpegData._readSOS (package:image/src/formats/jpeg/jpeg_data.dart:568:55)
#6      JpegData._read (package:image/src/formats/jpeg/jpeg_data.dart:338:11)
#7      JpegData.read (package:image/src/formats/jpeg/jpeg_data.dart:94:5)
#8      JpegDecoder.decodeImage (package:image/src/formats/jpeg_decoder.dart:46:10)
#9      decodeImage (package:image/src/formats/formats.dart:60:18)

Here is one such image:

test

Wrong RGB values from JPEG images

I'm experimenting with the JPEG decoder and there seems to be an issue with the RGB values.

I added this to the existing JPEG decode/encode test:

// Check RGB color extraction
expect(toRGB(image.getPixel(0, 0)), [48, 47, 45]);
expect(toRGB(image.getPixel(0, image.height)), [85, 81, 98]);
expect(toRGB(image.getPixel(image.width, 0)), [89, 103, 77]);
expect(toRGB(image.getPixel(image.width, image.height)), [40, 47, 39]);

where toRGB is simply defined as:

List<int> toRGB(int pixel) => [getRed(pixel), getGreen(pixel), getBlue(pixel)];

and the expected colors where extracted with GIMP.

The test fails right at the first pixel (0,0):

FAIL: JPEG decode/encode
Expected: [48, 47, 45]
Actual: [48, 46, 45]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.