2

I am Having PNG Image And Trying To Flop (Mirror) by imagick function of php It Gets Flop Exactly But The

Base Image is In Format 24 Bit RGB

and after Convertion It Gets To

8 Bit Pallated

. So the Main Problem is that when I use to place both images in my pdflib pages one of the image(converted) displays curly.... Original Image Original Image ----> Output After Flop(Mirror) by Imagick and Rendered in PDFlib -> Output After Flop(Mirror) by Imagick and Rendered in PDFlib ->

My Code Is Simple ---->

$im = new Imagick($background_image);
$im->flopImage();
$im->writeimage($background_image."_flop.png");

Modified Date => 29 Oct 2013 Original Image -> Size 4.68 KB Bit Depth 32 Flopped Image -> Size 7.99 KB Bit Depth 64 Automatically Changes It's Properties ORIGINAL ***ORIGINAL***

Converted ***Converted***

anshuVersatile
  • 398
  • 2
  • 13
  • Are you sure that the problem lies with Imagick, rather than when you're rendering the image in PDFLib? The original image you provided gets converted fine for me. – Danack Oct 28 '13 at 16:12
  • Hi Danack.... When I checked both images(Original & Converted) in photoshop it shows that ori--> 24 bit and conv--> 8 bit – anshuVersatile Oct 29 '13 at 02:36
  • Can you post the exact file after it's just been 'flopped'. The one you posted has been resized from the original, which suggests that there are other things going on with it. – Danack Oct 29 '13 at 03:21
  • Hi Danack!!! Thanks For Your Valuable Time... But Seems This Is Bug Like Something In Imagick Cause If I Use GD For This Image It Works Perfect Only Imagick Is Creating Fatal Image.... – anshuVersatile Oct 29 '13 at 10:10

1 Answers1

4

Imagick is using the smallest format possible to save the image. Saving in these formats all produce the same image but have the sizes:

  • Palette - 3.38kB
  • RGBA 32bit - 6.14kB
  • RGBA 64bit - 8.09kB

Saving to the smallest possible file is usually what people desire. However you can disable this in a couple of ways.

You can tell Imagick to use the same PNG format as the source image by setting the png:format option to png00. e.g.

$imagick = new Imagick(realpath("../images/FlopOriginal.png"));
$imagick->flopImage();
$imagick->setOption('png:format', 'png00');
$imagick->writeImage("../images/Flop.png");

The full options for png:format are png8, png24, png32, png48, png64, and png00.

Alternatively you can explicitly set the image format to use when saving the PNG file, through the png:bit-depth and png:color-type e.g.

$imagick = new Imagick(realpath("../images/FlopOriginal.png"));
$imagick->flopImage();
$imagick->setOption('png:bit-depth', '8');
$imagick->setOption('png:color-type', 6);
$imagick->writeImage("../images/Flop.png");

The color type values come from the libpng.h and are:

PNG_COLOR_TYPE_GRAY         0
PNG_COLOR_TYPE_RGB          2
PNG_COLOR_TYPE_PALETTE      3
PNG_COLOR_TYPE_GRAY_ALPHA   4
PNG_COLOR_TYPE_RGB_ALPHA    6

Both those methods produce a flopped image that is RGBA 32bit like the original image.

Danack
  • 24,939
  • 16
  • 90
  • 122
  • @anshuVersatile btw the images that it was producing before are valid and represent the same image as the 32bit file. It's probably a bug in pdflib that it's not opening the files correctly. – Danack Oct 29 '13 at 17:00
  • For Information --> PDFlib has no support for that bit depth so they got cracked..... But Now All Is Well... Rendering Smoothly... And One More --> Nice To Meet You .... – anshuVersatile Oct 29 '13 at 17:21