Jump to content

SOLVED - GD wont show image if called from higher dir


vanderlay

Recommended Posts

FIXED - need to ensure all paths a relative if using STYLE tags to call image via higher dir.... :-\


UPDATED - I got the file below to work if i called it as an image not as a file

callimage.html
[code]
<img src="image.php">[/code]
however now the image will only show if the script calling the image is in the same DIR as the image script, ie

works - displays image
www/callimage.html
www/image.php

does not display image (the script is called but no image displays)
www/callimage.html
www/images/image.php

is there a way to put the image into a $var or similar so the image can be called from another directory?

thanks
Art

Hello,

I am trying to get an image to resize using GD. The code works if the page sits alone

image.php
[code]
if(!extension_loaded('gd')){
    if(strtoupper(substr(PHP_OS,0,3)) == 'WIN'){
        dl('php_gd2.dll');
    }else{
        dl('gd.so');
    }
}

/* Set the width (in pixels) for the smaller version - we will calculate
  the smaller version height based on the dimensions of the source image
*/
$smallwidth = 100;

/* Create an image resource from the source graphic
*/
$im = ImageCreateFromGif('001.gif');

/* Get the source image dimensions: */
$srcwidth = ImagesX($im);
$srcheight = ImagesY($im);

/* By dividing our smaller version width by the source image width,
  we will have the correct proportion for the smaller version height: */

$proportion = $smallwidth / $srcwidth;
$smallheight = round($srcheight * $proportion);

/* Now we can create a new image resource for the smaller version: */

$small = ImageCreateTrueColor($smallwidth, $smallheight);

/* Finally, we can copy the contents of $im into $small
  and resize it at the same time: */

ImageCopyResized($small, $im, 0, 0, 0, 0, $smallwidth, $smallheight, $srcwidth, $srcheight);

/* Output to browser: */



header ("content-type: image/gif");
ImageGif($small);
/* Destroy the image resources */

ImageDestroy($im);
ImageDestroy($small);[/code]

however if a place any echo or html before the
[code]header ("content-type: image/gif");
ImageGif($small);[/code]
it generates an error or shows the image code(garbage?)
any code after the ImageGif($small); will not show at all.

Any advice on how i actually use this function as part of an .inc file would be great,
thanks
Art
well headers and GD arnt my area but this is what i am thinking:

the reason it isnt showing AFTER the ImageGif($small); is because the content-type is set to image, so therfor it cannot and will not display text because of this.
and i think this may be the same before the header when it shows garbage.

not sure, just what i think...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.