Jump to content

GD Image Creation


Miichael

Recommended Posts

Hello

I have a question regarding the GD library image creation functions.

I can create the images I want using the php library functions.  No problem.  The result is the image on a web page displayed in my browser.

However I cannot figure out how to capture said image and so I can place it on my web page where I want.

I've spen hours looking but can find no answers.  Can anyone offer any suggestions?

Thanks

Michael
Link to comment
Share on other sites

What you want is something like this in your HTML...

[code]
<img src="imagecreator.php">
[/code]

...where imagecreator.php is the script that actually outputs the image.  You can of course pass in GET variables on a quiery string like...

[code]
<img src="imagecreator.php?bgcol=white&fgcol=green">
[/code]

...which is nice! :)
Link to comment
Share on other sites

Another alternative, if you want to use it in multiple places, you could create the image like you are and save it.

Depending on the type of image you're creating, you'll have a line that looks something like this, that outputs the image to the browser:

[code=php:0]imagejpeg($im);[/code] or
[code=php:0]imagejpeg($im, null, 100);[/code]

By changing, or adding the second parameter, you can save the image.

[code=php:0]$filename = '/home/domains/domain.co.uk/images/dynamic.jpg';
imagejpeg($im, $filename, 100);[/code]

Regards
Huggie
Link to comment
Share on other sites

Thanks

Both suggestions are good.  I actually tried '<img src="imagecreator.php">' as it is most appropriate for my needs.

And when the code renders I get a broken image symbol and the the html code is '<img src="imagecreator.php">'

For some reason the php script will not be invoked, but I know it is ok because if I call it directly the image is created and displayed.

Link to comment
Share on other sites

I must really be doing something wrong, 'cause I did that also.

Basically my code looks like this

the referenenced php file:

<?php

$im = imagecreatefrompng("path/iimage_name");

//some processing going on... (and I've deleted the processing in my test case to eliminate an error injection there)

header("Content-type: image/png");
imagepng($im);
ImageDestroy($im);
?>

in the calling program, in php I have the following code (I'm using the phpBB template)

$processed_image = '<img src="includes/make_the_image.php" alt="">'

and then

'"I_IMAGE' => $processed_image

and in my template file the code is

{I_IMAGE}

and when I render my code looks like:

<img src="includes/make_the_image.php" alt=""> and of course yields a broken image

Ive played around with the php code, for example trying to something like

src = "' . includes/make_the_image.php . ' "

and

src = "' . includes(includes/make_the_image.php) . '"

but to no avail.  I'm sure I'm missing something really simple (or have yet to learn it, this is my first time trying this kind of thing, but darned if I've seen it yet.

Thank you for your responses.

Mike
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.