Getting an image to output to a page

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Posts: 8
Joined: 2017-02-24T03:49:36-07:00
Authentication code: 1151

Getting an image to output to a page

Post by hivens » 2017-03-01T14:06:24-07:00


I'm having trouble getting my head around this. I generate an image but I want to show it on an HTML page. So far I have something like this:

Code: Select all

<form method="post" action="myapp.php">
    <input type="text" name="name">
    <input name="colour" type="radio" value="1">Red<br>
    <input name="colour" type="radio" value="2">Blue<br>
    <input name="colour" type="radio" value="3">Green<br>
    <input type="submit" value="Submit" name="submit">

function display()
	$textdata = $_POST["name"];
	$colourdata = $_POST["colour"];
	$image = new Imagick();
	$image->newPseudoImage(500, 500, 'gradient:#3a7bd5-#3a6073');
	header('Content-type: image/png');
 	echo $image;
My function seems to generate an image ok, in theory, but how do I actually display it on the page? There seems to be three ways:

1. Stream it to a file using a separate image.php file, which is called a bit like this <img src="image.php">
2. Output it was base64
3. Write it to a file

I'm not really sure what is the best way, because I'm wondering if base64 and writing it to a file and then reading it have a bit more of a performance overhead than steaming it - but for the image.php I don't really know how if it's good practice to be trying to send parameters to a php function within an image (which I want to get next to set the text etc)

Any guidance would be appreciated.

Post Reply