How to code a transparent gradient using imagick in php?

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

How to code a transparent gradient using imagick in php?

Post by linjuming »

How to code a transparent gradient using imagick in php?

Image
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How to code a transparent gradient using imagick in php?

Post by magick »

Code: Select all

<?php
  $image = new Imagick();
  $image->setSize(300,300);
  $status = $image->readImage('gradient:cyan-none');
  $status = $image->writeImage('gradient.png');
?>
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

Re: How to code a transparent gradient using imagick in php?

Post by linjuming »

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

Re: How to code a transparent gradient using imagick in php?

Post by linjuming »

Please have a look at this example:
http://www.eclecticdjs.com/mike/tutoria ... /index.php
test in my computer :
the background should be transparent which is black ,why?


Image
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How to code a transparent gradient using imagick in php?

Post by magick »

Try the PNG32 format rather than PNG.
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

Re: How to code a transparent gradient using imagick in php?

Post by linjuming »

how ? can you write down the code? how to output a png32?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How to code a transparent gradient using imagick in php?

Post by magick »

Use $im->setImageFormat('PNG32');
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

Re: How to code a transparent gradient using imagick in php?

Post by linjuming »

black as the same result.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How to code a transparent gradient using imagick in php?

Post by magick »

Let's try from the command:
  • convert -size 100x100 gradient:red-transparent gradient.png
Does that work? If not, it could be your version of ImageMagick. We're using ImageMagick 6.6.7-2 and it produces an increasingly transparent gradient as expected for bother the command line and with Imagick.
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

Re: How to code a transparent gradient using imagick in php?

Post by linjuming »

Yes , it works in command line.
Thank you very much.

but i doubt whether it can use in ajax if I use command line.

Code: Select all

<?php
	$width="300";
	exec("convert -size {$width}x100 gradient:red-transparent gradient.png");
	if(file_exists("gradient.png")){
		echo "yes";
	}
?>
the code above can echo "yes";if there are many many comand lines to operate an image,can it be ok?
Post Reply