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);
}
///////////////////////////////////////////////////////////////
Why the output image is so big
Re: Why the output image is so big
Use MagickSetImageType() to create a colormapped image which reduces the PNG size but does lose some color information.
- 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
add -depth 8 perhaps