Solved

img src

Posted on 2014-12-01
10
66 Views
Last Modified: 2015-01-08
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
0
Comment
Question by:tonelm54
10 Comments
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
You could try this:

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

Open in new window


Cheers
0
 
LVL 9

Expert Comment

by:Brian Tao
Comment Utility
The problem is in your getImgLogo.php and not in your img tag.  Please post the php code so that people can help.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
0
 

Author Comment

by:tonelm54
Comment Utility
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
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
Works perfectly when you change "logoID=3" to "logoID=2" so it looks for the right image.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:tonelm54
Comment Utility
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
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
No, your test site works just fine from here in Chrome and Firefox.
0
 

Accepted Solution

by:
tonelm54 earned 0 total points
Comment Utility
I actually found the issue and now it works with all browsers.

The issue was with the line:-
header("Content-Length: " . filesize($filename));  

Open in new window


When I removed it, it works fine. I dont understand why though, or why it works on your browsers and not mine
0
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 500 total points
Comment Utility
Very puzzling because that is not done in the browser but on the server.
0
 

Author Closing Comment

by:tonelm54
Comment Utility
Found the problem myself, but thank you for your assistance
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now