How can I convert grayscale blob to PNG?

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
star117
Posts: 5
Joined: 2016-03-28T02:19:31-07:00
Authentication code: 1151

How can I convert grayscale blob to PNG?

Post by star117 »

HI!
I find way to convert 16 bits grayscale blob to PNG image from file:

Code: Select all

      convert -size 600x600 gray:rawdata.dat -depth 16 out.png
its working.
But I want to make this by PHP extension Imagick. Its not working.

Code: Select all

$fill="...long string witch have 16 bits pairs of grayscale...";
$im=new Imagick();
$im->setResolution($width,$height);
$im->readImageBlob($fill);
...exception...
in readImageBlob(...) I see exception:

Code: Select all

PHP Fatal error:  Uncaught exception 'ImagickException' with message 'no decode delegate for this image format `' @ error/blob.c/BlobToImage/364' in ...
Question is: How can I read blob (and convert to png, off course) with Imagick as in ImageMagick CLI?

P.S.: rawdata.dat and $fill have same data.
Last edited by star117 on 2016-03-28T06:19:54-07:00, edited 3 times in total.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Convert grayscale blob to PNG

Post by dlemstra »

I am not an IMagick expert but I suspect you must tell it the format first. It looks like you can do that with $im->setFormat("gray").
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
star117
Posts: 5
Joined: 2016-03-28T02:19:31-07:00
Authentication code: 1151

Re: Convert grayscale blob to PNG

Post by star117 »

Yes, I agree with you. But then I try to setFormat() Imagick throw exception like "Can not process empty Imagick object"...
star117
Posts: 5
Joined: 2016-03-28T02:19:31-07:00
Authentication code: 1151

Re: Convert grayscale blob to PNG

Post by star117 »

Anyone can help? Maybe guru
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How can I convert grayscale blob to PNG?

Post by Bonzo »

Imagick is not written or maintained by the Imagemagick developers and there are a very few users here. I think I have seen an Imagick forum somewhere and it might be best asking them.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can I convert grayscale blob to PNG?

Post by snibgo »

I've never used Imagick, but the documentation http://php.net/manual/en/imagick.setsize.php says you need "setSize()".

"setResolution()" corresponds to command-line "-density" which is unimportant. At the CLI, "-size" is essential for raw images because there is no widthXheight metadata.
snibgo's IM pages: im.snibgo.com
star117
Posts: 5
Joined: 2016-03-28T02:19:31-07:00
Authentication code: 1151

Re: How can I convert grayscale blob to PNG?

Post by star117 »

snibgo wrote:I've never used Imagick, but the documentation http://php.net/manual/en/imagick.setsize.php says you need "setSize()".

"setResolution()" corresponds to command-line "-density" which is unimportant. At the CLI, "-size" is essential for raw images because there is no widthXheight metadata.
HI!
I try to setSize() before make readImageBlob() with same result, that's doesn't work.
I started thinking about I cannot make it in Imagick.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can I convert grayscale blob to PNG?

Post by snibgo »

What does your code now contain? What is the error message? What version of ImageMagick are you using?
snibgo's IM pages: im.snibgo.com
star117
Posts: 5
Joined: 2016-03-28T02:19:31-07:00
Authentication code: 1151

Re: How can I convert grayscale blob to PNG?

Post by star117 »

snibgo wrote:What does your code now contain? What is the error message? What version of ImageMagick are you using?

Code: Select all

...
$im=new Imagick();
$im->setSize($width,$height);
$im->readImageBlob($fill);
// формат
$im->setImageFormat("png");
$im->setOption('png:bit-depth', "16");
$im->setOption('png:color-type', 5);
$im->writeImage($outfpath);
$im->destroy();
...
Error is:

Code: Select all

PHP Fatal error:  Uncaught exception 'ImagickException' with message 'no decode delegate for this image format `' @ error/blob.c/BlobToImage/364' in ...
error occured in line with readImageBlob(...).

$fill - is string contains sequence pairs of symbols represented value of 16 bit big-endian.

Code: Select all

Imagick version: array (
  'versionNumber' => 1655,
  'versionString' => 'ImageMagick 6.7.7-10 2014-03-08 Q16 http://www.imagemagick.org',
)
Have some ideas?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can I convert grayscale blob to PNG?

Post by snibgo »

Why don't you set the format to "gray" before reading it?
snibgo's IM pages: im.snibgo.com
Post Reply