Page 1 of 1

Why the output image is so big

Posted: 2009-07-08T00:12:09-07:00
by seaskysmile
I write a program to convert other format image to PNG format.
I find its outputing image size is more large than the image output by the tool named convert.
My program is named pic_convert
./pic_convert pic.jpg pic_convert.png

pic_convert.jpg size: 25945

convert pic.jpg -adaptive-resize 100x100 -type Palette convert.png

convert.png size:6624

the size of pic.jpg is 34609

Maybe, the function MagickSetImageType(magick_wand, PaletteType) is not work well.

WHY?

my code:
//////////////////////////////////////////////////////////

int main(int argc, char * argv[])
{

MagickBooleanType
status;

MagickWand
*magick_wand;

if (argc != 3)
{
printf("Usage: %s image thumbnail\n",argv[0]);
return 1;
}
/*
Read an image.
*/
MagickWandGenesis();

magick_wand=NewMagickWand();
status=MagickReadImage(magick_wand,argv[1]);

if (status == MagickFalse)
{
printf("read image failed.\n");
return 1;
}
/*
Turn the images into a thumbnail sequence.
*/
MagickSetImageType(magick_wand, PaletteType);
MagickResetIterator(magick_wand);
while (MagickNextImage(magick_wand) != MagickFalse)
MagickAdaptiveResizeImage(magick_wand,100,100);
/*
Write the image then destroy it.
*/
status=MagickWriteImages(magick_wand,argv[2],MagickTrue);
if (status == MagickFalse)
{
printf("write image failed.\n");
return 1;
}
magick_wand=DestroyMagickWand(magick_wand);
MagickWandTerminus();
return(0);

}

///////////////////////////////////////////////////////////////

Re: Why the output image is so big

Posted: 2009-07-08T05:58:33-07:00
by magick
Use MagickSetImageType() to create a colormapped image which reduces the PNG size but does lose some color information.

Re: Why the output image is so big

Posted: 2009-07-08T09:04:13-07:00
by fmw42
add -depth 8 perhaps

Re: Why the output image is so big

Posted: 2009-07-08T21:57:41-07:00
by seaskysmile
I make it.

Thanks to all of you!