Image shows in binary.. with code

images php coding issues or problems here.

Moderators: macek, egami, gesf

pungball
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Aug 17, 2004 3:12 am

Image shows in binary.. with code

Postby pungball » Tue Aug 17, 2004 6:25 am

Hi!

I have a problem!

When I try the code below the picture is shown as binary. The script puts a logo down in the right corner of a picture. The script works by itself...

I also get the "Warning: Cannot modify header information - headers already sent by ..." when I use <html><head> etc...

I have to have this picture down in the page in a table...

Anyone? thanks!

<?php
$sql = "select dato,navn,path,undertekst,bruker from bilder where id='$id'";
$result = mysql_query ($sql,$conn);

if (!$result = mysql_query($sql)) { die("En feil har oppstått: ".$mysql_error."<BR>\n"); }
while($myrow = mysql_fetch_row($result)) {
$dato = $myrow[0];
$navn = $myrow[1];
$path = $myrow[2];
$undertekst = $myrow[3];
$bruker = $myrow[4];

print "<center><table width=30% border=0 cellspacing=1 cellpadding=0 bgcolor='$bgcolor1'>";
print "<tr bgcolor='$tableback1'><td>";


//here's the prob

$hovedfil = $path . $navn;
$size1=getimagesize($hovedfil);
$width1=$size1[0];
$height1=$size1[1];

$size2=getimagesize("logo.png");
$width2=$size2[0];
$height2=$size2[1];

$startlogo_x = $width1 - $width2;
$startlogo_y = $height1 - $height2;

header("Content-type: image/jpeg");

$im1 = imagecreatefromjpeg($hovedfil);
imagealphablending($im1, true); // this has to be before imagecopy();
$im2 = imagecreatefrompng("logo.png");
imagecopy($im1,$im2,$startlogo_x,$startlogo_y,0,0,$width2,$height2);
imagejpeg($im1,'',90);
imagedestroy($im1);
imagedestroy($im2);


// stop prob.


"</td></tr>";
print "<tr bgcolor='$tableback2'><td><i><b>$undertekst</b></i><br>Lagt inn av $bruker.</td></tr>";
print "</table>";
print "</center>";
?>

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Postby swirlee » Tue Aug 17, 2004 6:54 am

You're trying to output the image data in the middle of your HTML. You can't do that. Either your PHP script needs to generate an image (and be called in an img tag, e.g. <img src="script.php"/>), or it needs to save the image somewhere and you need to use the name in your img tag. You can't output both HTML and an image in the same script.

pungball
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Aug 17, 2004 3:12 am

Postby pungball » Tue Aug 17, 2004 7:17 am

Do you mean that i could do like this:

print "<tr bgcolor='$tableback1'><td><img src='inc/img.php'></td></tr>";


?

That would be the ideal, but don't know how to make that work...

The other way seems to me like some use of imagecreate() or something similar, but i'd rather use the first way...

thanks for quick response though!

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Postby ruturajv » Wed Aug 18, 2004 8:23 pm

yes keep the file that generates the images apart from the html file

so what you've done in the second version is correct.
<img src="http://localhost/imgfile.php?fileid=23" />
something like that...


Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 1 guest