Miichael Posted January 24, 2007 Share Posted January 24, 2007 HelloI 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?ThanksMichael Quote Link to comment https://forums.phpfreaks.com/topic/35476-gd-image-creation/ Share on other sites More sharing options...
bqallover Posted January 24, 2007 Share Posted January 24, 2007 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! :) Quote Link to comment https://forums.phpfreaks.com/topic/35476-gd-image-creation/#findComment-167928 Share on other sites More sharing options...
HuggieBear Posted January 24, 2007 Share Posted January 24, 2007 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]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/35476-gd-image-creation/#findComment-167945 Share on other sites More sharing options...
Miichael Posted January 24, 2007 Author Share Posted January 24, 2007 ThanksBoth 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. Quote Link to comment https://forums.phpfreaks.com/topic/35476-gd-image-creation/#findComment-168040 Share on other sites More sharing options...
HuggieBear Posted January 24, 2007 Share Posted January 24, 2007 You must output a header in imagecreator.php, like this:[code=php:0]header("Content-type: image/jpg");[/code]Of course this will change depending on the type of image you're outputting.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/35476-gd-image-creation/#findComment-168089 Share on other sites More sharing options...
Miichael Posted January 24, 2007 Author Share Posted January 24, 2007 I must really be doing something wrong, 'cause I did that also.Basically my code looks like thisthe 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_imageand 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 imageIve played around with the php code, for example trying to something likesrc = "' . 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 Quote Link to comment https://forums.phpfreaks.com/topic/35476-gd-image-creation/#findComment-168145 Share on other sites More sharing options...
HuggieBear Posted January 25, 2007 Share Posted January 25, 2007 The code you have looks fine, and if you view the source and get the result that you've pasted then the only conclusion is that the 'processing' you've cut out is causing an issue of some kind.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/35476-gd-image-creation/#findComment-168795 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.