Anyone here know how to use MagickWand with PHP?

  • Thread starter Thread starter Bes
  • Start date Start date

Bes

Bes

Soldato
Joined
18 Oct 2002
Posts
7,318
Location
Melbourne
Hi

I am trying to blob the image being held in memory (after processing) as part of an HTML page, but I cannot get it to work as it is expecting the doctype to be image/gif when it is in fact HTML. All I get is either the image and no HTML, or HTML and junk where the image should be.

This is the problematic line:
PHP:
MagickEchoImageBlob( $resource );

There must be a solution for this, but having searched high and low, I cannot find one?!

Thanks
 
You can't output raw image data into an HTML page*. Output it in its own file (with the correct image mimetype sent) and then link to that page from your HTML using an <img> tag.

So, in foo.php:

Code:
<?php
/* snip */
header('Content-Type: image/gif');
MagickEchoImageBlob($resource);
?>

and in foo.html:

Code:
<img src="foo.php" alt="" />

*You can technically base64 it and include it as a data: URI, but that's not supported in IE.
 
Hmm thanks but.......

I am basically trying to do something where the user can click buttons and stuff to adjust the image properties and preview it in the browser as they go... I am going to struggle to pass what is essentially commands in the GUI from one page to another page that is going to eventually spit out the finished image I think?

I can't use cookies as I envisage the final solution will be used mainly in public Internet Access points/ Internet Cafes with cookies disabled.

Edit:

Ahhh hang on if I did my 'editing suite' and submitted the data as a set of form elements to the PHP page (foo.php containing all my commands and the output image), could I then get this to work?

Thanks
 
Last edited:
pass values to the image script via the url like this -

<img src="foo.php?height=100&width=200" />

then in foo.php

$height = $_GET['height'];

and so on.....
 
Yep, do what Marc said. Remember to bounds-check your input, though—you probably don't want users being able to create and manipulate 100,000×100,000 pixel images and take your server out!
 
Sorry guys I am kind of new to this..

When the user hits submit, I need to have all the stuff passed to the image tag like above in order to get the custom transformations done, but how is this actually done? I mean do I submit all the form values to a javascript, then have them write the tag in or something?

Thanks
 
you could post the values to a page and generate the <img> tag from the form values.

Code:
echo '<img src="foo.php?height=' . $_POST['height'] . '&width=' . $_POST['width'] . '" />';

as mentioned above, you'll want to validate these somewhere along the line - if the value is out of bounds, just set a default....:)
 
Back
Top Bottom