[magick-users] MagickTrimImage() problem/bug?
Christian Magnusson
mag at mag.cx
Tue Sep 23 02:59:42 PDT 2008
Hi there,
I have tried to create an application which is supposed to download TV-guide
images, and later trim, crop and resize them.
It seems to be some problem with the MagickWand-object after I have
successfully called MagickTrimImage(). If the image was trimmed to a smaller
size, MagickCropImage() returns a malformed image.
Should be MagickWand be updated in some way after MagickTrimImage() is
called? I have seen some convert scripts which call "+repage", but are
there any similar functions that should be used?
Can anyone give me some hints if it's a bug in ImageMagick, or if I should
try some other method.
/Christian
BTW: I have used ImageMagick-6.4.3-8.tar.gz during my tests
-----------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <wand/MagickWand.h>
/*
This example describes that MagickCropImage() fails after MagickTrimImage
has been called (and trimmed the images to a smaller size)
Compile with:
# gcc -g `MagickWand-config --cflags --cppflags` -o convert_bug
convert_bug.c `MagickWand-config --ldflags --libs` -Wl,-rpath,/usr/local/lib
# wget http://xmltv.tvsajten.com/chanlogos/sport2.viasat.se.png
# wget http://xmltv.tvsajten.com/chanlogos/tv3.viasat.se.png
# wget http://xmltv.tvsajten.com/chanlogos/hits.canalplus.se.png
(This first example works since the trimmed image has the same size)
# ./convert_bug tv3.viasat.se.png
original size w=100 h=100
trimmed image to w=100 h=100
Try crop image to w=50 h=100
cropped image to w=50 h=100
(This example fails and results into a 1x1 image)
# ./convert_bug hits.canalplus.se.png
original size w=100 h=100
trimmed image to w=99 h=12
Try crop image to w=49 h=12
cropped image to w=1 h=1
(This example fails and results into a 50x34 image (instead of 50x56))
# ./convert_bug sport2.viasat.se.png
original size w=100 h=100
trimmed image to w=100 h=56
Try crop image to w=50 h=56
cropped image to w=50 h=34
*/
#define ThrowWandException(wand) \
{ \
char \
*description; \
\
ExceptionType \
severity; \
\
description=MagickGetException(wand,&severity); \
(void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
description=(char *) MagickRelinquishMemory(description); \
exit(-1); \
}
int main(int argc,char **argv)
{
MagickBooleanType status;
MagickWand *src_wand;
if (argc != 2) {
(void) fprintf(stdout,"Usage: %s image\n",argv[0]);
exit(0);
}
MagickWandGenesis();
src_wand=NewMagickWand();
status=MagickReadImage(src_wand,argv[1]);
if (status == MagickFalse)
ThrowWandException(src_wand);
printf("original size w=%d h=%d\n", MagickGetImageWidth(src_wand),
MagickGetImageHeight(src_wand));
/* Trim the image and remove border */
status = MagickTrimImage(src_wand,10);
if (status == MagickFalse)
ThrowWandException(src_wand);
printf("trimmed image to w=%d h=%d\n", MagickGetImageWidth(src_wand),
MagickGetImageHeight(src_wand));
/* crop the left part of the image */
printf("Try crop image to w=%d h=%d\n", MagickGetImageWidth(src_wand)/2,
MagickGetImageHeight(src_wand));
status = MagickCropImage(src_wand, MagickGetImageWidth(src_wand)/2,
MagickGetImageHeight(src_wand), 0, 0);
if (status == MagickFalse)
ThrowWandException(src_wand);
printf("cropped image to w=%d h=%d\n", MagickGetImageWidth(src_wand),
MagickGetImageHeight(src_wand));
status = MagickWriteImages(src_wand,"new.png",MagickTrue);
if (status == MagickFalse)
ThrowWandException(src_wand);
src_wand = DestroyMagickWand(src_wand);
MagickWandTerminus();
return(0);
}
More information about the Magick-users
mailing list