phat_hip_prog Posted April 2, 2007 Share Posted April 2, 2007 Hi, i'm playing with a small cms. It uses mod_rewrite to redirect to an index, however in certain circumstances I want to generate images using gd, needing to send appropiate headers first i've put a clause in very early, even before 'session_start()'. Instead a function which generates and returns an image is called. However all I get is the filename, why? I've tested the image creation in files outside the cms and it works fine... But inside the cms it borks! Here's how i've simplified it for tests: index.html <?php include("monkey/inc.php"); $iret = inc_init(); if($iret != -1) { print inc_draw(); // generate page } ?> Here's the 'inc_init()' and 'draw_img()' functions: monkey/inc.php function draw_img() { header("Content-type: image/jpeg"); $w = 230; $h = 45; $im = ImageCreate($w, $h); $red = ImageColorAllocate($im, 255, 50, 50); // DRAW BACKGROUND ImageFilledRectangle($im, 0, 0, $w, $h, $red); // OUTPUT TO BROWSER ImageJpeg($im); } function inc_init() { // CHECK IMAGE GENERATOR OVERRIDE if (isset($_GET["page"])) { $p = $_GET["page"]; $lret = split_url($p); // dir, dirs, fn, bn, ext if ($lret['dirs'][0] == "img") { draw_img(); return -1; } } // LOAD MODS inc_load_mods(); ... ... Can anyone tell me why all i'm getting is the filename printed to screen? Cheers! Link to comment https://forums.phpfreaks.com/topic/45309-gd-generation/ Share on other sites More sharing options...
Barand Posted April 2, 2007 Share Posted April 2, 2007 Treat php-generated images as you would any other image file. Put the gd code in a separate php file, say, myimage.php, and place it on the page with an image tag, eg <img src='myimage.php'> Link to comment https://forums.phpfreaks.com/topic/45309-gd-generation/#findComment-220006 Share on other sites More sharing options...
phat_hip_prog Posted April 2, 2007 Author Share Posted April 2, 2007 Because of the way i've got mod_rewrite setup I can't just call the file. I've tried calling the file using both 'include()' and 'eval()', both ways give the same result. But from what I see theres no real need to have them in a seperate file? any more for any more? Link to comment https://forums.phpfreaks.com/topic/45309-gd-generation/#findComment-220017 Share on other sites More sharing options...
MadTechie Posted April 2, 2007 Share Posted April 2, 2007 What!!! don't include it or anything just use <img src='myimage.php'> Link to comment https://forums.phpfreaks.com/topic/45309-gd-generation/#findComment-220019 Share on other sites More sharing options...
phat_hip_prog Posted April 2, 2007 Author Share Posted April 2, 2007 It is called like that (<img src='img/myimage.php'>), then mod_rewrite translates it to 'index.html?page=img/myimage.php', $page is then split and checked, when discoved it's 'img', either the file is included or the function called. This is all done as if it was in a file on it's own? Link to comment https://forums.phpfreaks.com/topic/45309-gd-generation/#findComment-220032 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.