Re: PHP-gen'd images won't display in HTML



Hi,

I've tested your script on my localhost. It worked perfectly fine with
<img> tag carrying src='myimage.php'. As per zorro's suggestion I added
one blank space on top of the file, before <?php, and it failed. So
please make there is no blank space or any sort of output. As you are
calling header() you should remember it cannot have any kind of output
before you call functions like header(), session_start().

Thank you.

Ehsan
http://ehsan.bdwebwork.com/

On Dec 28, 2:42 pm, "CPD" <n...@xxxxxxxx> wrote:
I have an image-generating script myimage.php that's worked and that I've
used for years. All it does is increment a counter file and output a single
pixel in the color I provide. But on one particular web server I uploaded
to, the behavior is strange.

If I enter the URLhttp://www.domain.ext/myimage.php, the picture is
displayed as expected. But if I insert the script into HTML, like <img
src="myimage.php">, it fails to display and I get the broken image icon,
instead.

This has never happened before, but I do not know enough about PHP builds
and web server settings to figure this out.

Any suggestions? Thanks for any help!

Here's the code, if necessary:

$filename = trim($_GET['filename']);
$color = (trim($_GET['color']) == "") ? "000000" : trim($_GET['color']);

$count = '0';
$file_last_mod = 0;

// Set up filename whether or not provided

if(strlen($filename)) {
$filename .= ".count";}else {
$fname_end = strrpos($script_name, ".");
$fname_end = ($fname_end === false) ? strlen($script_name) :
$fname_end - 1;
$slash_pos = strrpos($script_name, "/");
$fname_start = ($slash_pos === false) ? 0 : $slash_pos + 1;
$script_name = (!strlen($filename)) ? $HTTP_SERVER_VARS['SCRIPT_NAME'] :
$filename;
$filename = substr($script_name, $fname_start, $fname_end - $slash_pos)
. ".count";

}// open and read file if it exists

if (file_exists($filename)) {
$file_last_mod = filemtime($filename);
$count = file_get_contents($filename);

}// increment count

$count += 1;

// reopen file and write new count

$handle = fopen($filename, "w");
fwrite($handle, $count);
fclose($handle);

// Generate a 1 x 1 pixel image

$im = @imagecreate(1, 1)
or die("<!-- Cannot Initialize new GD image stream -->");

// Set up color if not provided

if (!strlen(trim($color))) $color = "000000";

// Set image color

$red = 0 + base_convert(substr($color, 0, 2), 16, 8);
$green = 0 + base_convert(substr($color, 2, 2), 16, 8);
$blue = 0 + base_convert(substr($color, 4, 2), 16, 8);
$img_color = imagecolorallocate($im, $red, $green, $blue);

// Output the created image according to available GD image support

if (function_exists("imagegif")) {
header("Content-type: image/gif");
imagegif($im);} elseif (function_exists("imagejpeg")) { header("Content-type: image/jpeg");
imagejpeg($im);} elseif (function_exists("imagepng")) { header("Content-type: image/png");
imagepng($im);} elseif (function_exists("imagewbmp")) { header("Content-type: image/vnd.wap.wbmp");
imagewbmp($im);} else { die("<!-- No image support on this PHP server -->");

}

.



Relevant Pages

  • Re: using xml to save/open project data
    ... http://www.TransProCalc.org - Free translation project mgmt software ... set filename tk_getOpenfile ... Exec'ing the script you run it as a separate process, your script won't be able to access its vars. ... generating the xml file is easy enough. ...
    (comp.lang.tcl)
  • Re: Web Help
    ... And save it as "certificate.php" on your web server. ... do to get around the limitations with IWP reports is to build your own. ... and the "Go to URL" script step. ... Printing from the web is not the best as you can not compress ...
    (comp.databases.filemaker)
  • Re: Help me find 5 mistakes and than solution to thoes mistakes!
    ... > 8:# This script will create links to files from all of the filename ... > 10:# arguments provided on stdin if no filenames provided on command ...
    (Fedora)
  • Re: MIME - scripting and symbol substitutions
    ... This script is creating a text file with a different filename ... symbol called NEWFILENAME (which works, ... MIME from the command line with all options (so normal DCL ...
    (comp.os.vms)
  • Script using dll and ocx (to integrate in IIS )
    ... I have a script for an Motion Jpeg that I have to integrate into a website ... to get a "live Image" from a network camera. ... But in this script I have to install a dll and an oxc on my ... Create a Web Server alias and use this as the image ...
    (microsoft.public.inetserver.iis.ftp)