Page 1 of 1

an instance of ImagickPixel ?

Posted: 2011-03-19T20:05:30-07:00
by linjuming

Code: Select all

<?php
	$width		= 100;
	$height		= 200;

	$im=new Imagick();
	$im->newimage($width,$height,"red");

	$im->writeimage("img/selected_overlay/selected_overlay.gif");

?>
error info:

Catchable fatal error: Argument 3 passed to Imagick::newimage() must be an instance of ImagickPixel, string given in D:\phpnow\htdocs\mycenter\oocss\create_selected_overlay.php on line 7

old version is ok ,but error occurs in the lastest version .how to fix?

Re: an instance of ImagickPixel ?

Posted: 2011-03-19T20:12:13-07:00
by fmw42

Re: an instance of ImagickPixel ?

Posted: 2011-03-19T20:20:14-07:00
by linjuming

Code: Select all

<?php
	@$width		= $_POST["width"];
	@$height	= $_POST["height"];
	$width		= 100;
	$height		= 200;

	$im=new Imagick();
	$color=new imagickpixel("rgb(0,0,0,0)");
	$im->newimage($width,$height,$color);
	$im->setimageformat("png32");
//	header( "Content-Type: image/gif" );
//	echo $im;

	$im->writeimage("img/selected_overlay/selected_overlay.png");

?>
why is the created png black ? my imagick version is the latest now .

Re: an instance of ImagickPixel ?

Posted: 2011-03-19T20:23:00-07:00
by fmw42
you did not pay attention to the example I reference above. Here it is:

<?php

$image = new Imagick();
$image->newImage(100, 100, new ImagickPixel('red'));
$image->setImageFormat('png');

header('Content-type: image/png');
echo $image;

?>

Re: an instance of ImagickPixel ?

Posted: 2011-03-19T20:25:06-07:00
by linjuming
i want to get a completely transparent png ,not red , i am sorry i did not modify the color name before.

tried "none" and "transparent" ,the result is black as the same.

Re: an instance of ImagickPixel ?

Posted: 2011-03-19T21:02:37-07:00
by fmw42
try enabling the alpha channel first, see http://us3.php.net/manual/en/function.i ... hannel.php

or better

replace

$color=new imagickpixel("rgb(0,0,0,0)");

with

$color=new imagickpixel("rgba(0,0,0,0)");

Re: an instance of ImagickPixel ?

Posted: 2011-03-19T21:12:02-07:00
by linjuming
thank you ! all is ok.

Re: an instance of ImagickPixel ?

Posted: 2011-03-19T21:38:22-07:00
by fmw42
glad that helped. it is a common mistake that even I have done from time to time.