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
HTMLPHP

Avatar of undefined
Last Comment
tonelm54

8/22/2022 - Mon
Marco Gasi

You could try this:

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

Open in new window


Cheers
Brian Tao

The problem is in your getImgLogo.php and not in your img tag.  Please post the php code so that people can help.
Dave Baldwin

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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
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
Dave Baldwin

Works perfectly when you change "logoID=3" to "logoID=2" so it looks for the right image.
tonelm54

ASKER
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Dave Baldwin

No, your test site works just fine from here in Chrome and Firefox.
ASKER CERTIFIED SOLUTION
tonelm54

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
tonelm54

ASKER
Found the problem myself, but thank you for your assistance