Why the output image is so big

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
seaskysmile

Why the output image is so big

Post 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);

}

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

Re: Why the output image is so big

Post by magick »

Use MagickSetImageType() to create a colormapped image which reduces the PNG size but does lose some color information.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Why the output image is so big

Post by fmw42 »

add -depth 8 perhaps
seaskysmile

Re: Why the output image is so big

Post by seaskysmile »

I make it.

Thanks to all of you!
Post Reply