Page 1 of 1
How can I convert grayscale blob to PNG?
Posted: 2016-03-28T02:34:55-07:00
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.
Re: Convert grayscale blob to PNG
Posted: 2016-03-28T02:49:36-07:00
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").
Re: Convert grayscale blob to PNG
Posted: 2016-03-28T03:08:18-07:00
by star117
Yes, I agree with you. But then I try to setFormat() Imagick throw exception like "Can not process empty Imagick object"...
Re: Convert grayscale blob to PNG
Posted: 2016-03-28T06:17:57-07:00
by star117
Anyone can help? Maybe guru
Re: How can I convert grayscale blob to PNG?
Posted: 2016-03-28T07:35:24-07:00
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.
Re: How can I convert grayscale blob to PNG?
Posted: 2016-03-28T08:02:43-07:00
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.
Re: How can I convert grayscale blob to PNG?
Posted: 2016-03-28T23:40:57-07:00
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.
Re: How can I convert grayscale blob to PNG?
Posted: 2016-03-28T23:51:42-07:00
by snibgo
What does your code now contain? What is the error message? What version of ImageMagick are you using?
Re: How can I convert grayscale blob to PNG?
Posted: 2016-03-29T01:01:26-07:00
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?
Re: How can I convert grayscale blob to PNG?
Posted: 2016-03-29T10:16:05-07:00
by snibgo
Why don't you set the format to "gray" before reading it?