can't compress when using Pascal instead of command line

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
LorisF
Posts: 3
Joined: 2011-09-20T23:44:23-07:00
Authentication code: 8675308

can't compress when using Pascal instead of command line

Post by LorisF »

Hi,
I am new to ImageMagick so I am trying to learn to use the API with Pascal (Delphi XE) on Windows.
I want to convert a BMP to TIF black and white with LZW compression.

With this command line everything ok:

Code: Select all

>convert c:\temp\scanned.bmp -type bilevel -compress LZW c:\temp\scanned8.tif
But when I try to use this API (simplyfied)

Code: Select all

    status := MagickReadImage(wand, 'c:\temp\scanned.bmp');
    MagickSetImageType(wand, BilevelType);
    MagickSetImageCompression(wand, LZWCompression);
    status := MagickWriteImages(wand, 'c:\temp\scanned8.tif', MagickTrue);
The file il very little (less than 1Kb) and contain an image with everything black.
Well I can see a black image when opening the file with GIMP, if I open the same file with Windows preview the answer is "Preview not available".
Without the line "MagickSetImageCompression()" the file is correctly created, but is big, I want to obtain the compressed one.
Maybe I missed something?
Thanks
Loris

Version for command and for DLL used are the same: 6.7.2-7 Q16
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: can't compress when using Pascal instead of command line

Post by magick »

Type
  • identify -verbose scanned8.tif
does it report
  • Compression: LZW
LorisF
Posts: 3
Joined: 2011-09-20T23:44:23-07:00
Authentication code: 8675308

Re: can't compress when using Pascal instead of command line

Post by LorisF »

The command identify show some error,
the compression show is JPG, but also at the end "invalid strip"

Image: c:\temp\scanned8.tif
Format: TIFF (Tagged Image File Format)
[...]
Compression: JPEG
[..]
Filesize: 675BB
Number pixels: 4.76MB
Pixels per second: 50.64MB
User time: 0.094u
Elapsed time: 0:01.093
Version: ImageMagick 6.7.2-7 2011-09-16 Q16 http://www.imagemagick.org
identify: Invalid strip byte count 0, strip 0. `TIFFFillStrip' @ error/tiff.c/TIFFErrors/499.
identify: Invalid strip byte count 0, strip 1. `TIFFFillStrip' @ error/tiff.c/TIFFErrors/499.
[...]
... and so on form strip 0 to 58
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: can't compress when using Pascal instead of command line

Post by magick »

We're using ImageMagick 6.7.2-7 and this code:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wand/MagickWand.h>
#include <errno.h>

int main(int argc,char **argv)
{
  MagickBooleanType 
    status;

  MagickWand 
    *wand;

  MagickWandGenesis();
  wand=NewMagickWand();
  status=MagickReadImage(wand, "logo.bmp");
  MagickSetImageType(wand, BilevelType);
  MagickSetImageCompression(wand, LZWCompression);
  status=MagickWriteImages(wand, "logo.tif", MagickTrue);
  wand=DestroyMagickWand(wand);
  MagickWandTerminus();
  return(0);
}
It produces a LZW-compressed image as expected. Perhaps LZW compression is not enabled in the TIFF delegate library under Windows.
LorisF
Posts: 3
Joined: 2011-09-20T23:44:23-07:00
Authentication code: 8675308

Re: can't compress when using Pascal instead of command line

Post by LorisF »

I tried with version 6.7.0 Q16 but nothing different.
I don't know how to change the delegate library so I tried the other compression method.

Here the results:

LZWCompression -> file corrupted
NoCompression -> ok, obvously no compression
BZipCompression -> nothing append, equals to NoCompression
RLECompression -> nothing append, equals to NoCompression
ZipCompression -> nothing append, equals to NoCompression
Group4Compression -> nothing append, equals to NoCompression
FaxCompression -> nothing append, equals to NoCompression

LosslessJPEGCompression -> the compression worked (from 585Kb to 55Kb)
So I can use this method, for me this is enough.
regards.
Post Reply