an instance of ImagickPixel ?

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
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

an instance of ImagickPixel ?

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: an instance of ImagickPixel ?

Post by fmw42 »

linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

Re: an instance of ImagickPixel ?

Post 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 .
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: an instance of ImagickPixel ?

Post 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;

?>
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

Re: an instance of ImagickPixel ?

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: an instance of ImagickPixel ?

Post 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)");
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

Re: an instance of ImagickPixel ?

Post by linjuming »

thank you ! all is ok.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: an instance of ImagickPixel ?

Post by fmw42 »

glad that helped. it is a common mistake that even I have done from time to time.
Post Reply