Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

img src

Im trying to put in an image source as:-
<img src="../logos/getImgLogo.php?logoID=<?php echo $row['cid']; ?>" alt="Logo" />

Open in new window


However inside html doesnt display the image, instead just displays the image as if it doesnt exist, however if I goto the location where getImgLogo.php exists and load it works fine.

Im assuming the issue is that src doesnt know its a png file so cant display it. Is this correct and if so how can I tell it there is a PNG coming in like:-
<img src="data:image/png;../logos/getImgLogo.php?logoID=<?php echo $row['cid']; ?>" alt="Logo" />

Open in new window


or is there another issue?

Thank you
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

You could try this:

<?php $img = "../logos/getImgLogo.php?logoID=$row['cid']; ?>
<img src="<?php echo $img ?>" alt="Logo" />

Open in new window


Cheers
The problem is in your getImgLogo.php and not in your img tag.  Please post the php code so that people can help.
The PHP page must return the correct MIME type in a header for the image type to be recognized.  It also must be sent first before the image content.
header('Content-type: image/png'); 

Open in new window

Look at the first example on this page: http://php.net/manual/en/function.imagecreate.php
Avatar of tonelm54
tonelm54

ASKER

Im trying to show the image as:-
<HTML>
<HEAD>
</HEAD>
<BODY>
<img src="showImage.php?logoID=3" />
</BODY>
</HTML>

Open in new window


And the to get the image (simplified code):-
<?php
    if (file_exists($_GET['logoID'] . ".dat")) {
        $filename = $_GET['logoID'] . ".dat";
    } else {
        $filename = "noLogo.dat";
    }
    
    $savename = $_GET['logoID'] . ".png";
    
    header("Content-Type: image/png");
    header("Content-Length: " . filesize($filename));    
    //header("Content-Disposition: attachment; filename=". $row['name']);    
    
    list($width, $height) = getimagesize($filename);
    $newwidth = 50;
    $newheight = 30;
    
    $imgsrc = file_get_contents($filename);
    
    $thumb = imagecreatetruecolor($newwidth, $newheight);
    
    $source = imagecreatefrompng($filename);
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    
    imagepng($thumb);
    
    imagedestroy($thumb);
    imagedestroy($source);
?>

Open in new window


Ive attached the code, in the hope someone can help, please

Thank you
index.php
showImage.php
2.png
Works perfectly when you change "logoID=3" to "logoID=2" so it looks for the right image.
Sorry, uploaded a some wrong test data.

Im a bit confused, as when I upload it to a testing server I get the image load then disapear in chrome???

For example:-
http://test.uwh.tonycross.me.uk/imgSrc/index.php

But image loads fine:-
http://test.uwh.tonycross.me.uk/imgSrc/showImage.php?logoID=2

Very confused now :-S
No, your test site works just fine from here in Chrome and Firefox.
ASKER CERTIFIED SOLUTION
Avatar of tonelm54
tonelm54

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Found the problem myself, but thank you for your assistance