MagickGetSize always returns 0 height and 0 length

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
Bary

MagickGetSize always returns 0 height and 0 length

Post by Bary » 2007-01-01T06:18:52-07:00

Hey,
I wanna use MagickGetSize to get the size in pixels of an image in a wand, but the rows and the columns are every time zero.

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <wand/MagickWand.h>
#include <unistd.h>

int main()
{
        long colls, rows;

        MagickWand *wand;

        MagickWandGenesis();

        wand = NewMagickWand();
        MagickReadImage(wand, "test.jpg");
        MagickGetSize(wand, &colls, &rows);
        printf("columns: %ld rows: %ld\n", colls, rows);

        MagickWandTerminus();

        _exit(0);
}
The output is only: columns: 0 rows: 0


Thx in advance,
Bary

User avatar
magick
Site Admin
Posts: 10924
Joined: 2003-05-31T11:32:55-07:00

Post by magick » 2007-01-01T08:11:51-07:00

A common mistake that MagickWand and PerlMagick users makes is to assume that all calls to the API were successful. Add checks for success and display the exception if the method fails. For example,

Code: Select all

    status=MagickReadImage(magick_wand,"image.gif");
    if (status == MagickFalse)
      ThrowWandException(magick_wand);
where ThrowWandException () is

Code: Select all

  #define ThrowWandException(wand) \
  { \
    char \
      *description; \
   \
    ExceptionType \
      severity; \
   \
    description=MagickGetException(wand,&severity); \
    (void) fprintf(stderr,"%s %s %ld %s\n",GetMagickModule(),description); \
    description=(char *) MagickRelinquishMemory(description); \
    exit(-1); \
  }

Bary

The functions are working properly

Post by Bary » 2007-01-01T13:23:49-07:00

Thanks for your very fast answer, but this isn't the problem. There aren't any errors by the functions (and so ThrowWandException doesn't report any).


I also saved the read image at an other file name and this worked correctly, so the image is read as expected.


greetings

User avatar
magick
Site Admin
Posts: 10924
Joined: 2003-05-31T11:32:55-07:00

Post by magick » 2007-01-01T13:38:05-07:00

Ok, try
  • printf("columns: %ld rows: %ld\n", MagickGetImageWidth(wand),
    MagickGetImageHeight(wand));
The image size is a setting for raw image formats that do not include the size in the file headers such as raw red, green, blue image files.

Bary

It works

Post by Bary » 2007-01-01T14:40:13-07:00

Okay that works.

Thx

Post Reply