Jump to content

load image in html file...I know its been asked before


temjin

Recommended Posts

I know this has been asked before. I looked it up on the site but even copying the code and pasting it is not working. Here is my code, ALL OF IT. I just cant seem to load an image, no matter how simple I make the code:

 

<html>

<?php

header('Content-Type: image/jpeg');

$image = open_image($image);

if ($image === false) { die ('Unable to open image'); }

// ... Do some manipulation here ...

// Send header

// Display image

 

function open_image ($file) {

        $im = @imagecreatefromjpeg('Spiderman_3.jpg');

if ($im === false) {

        die ('Unable to open image');

}

echo 'Opened image';

}

?>

<head>

<title>Untitled Document</title>

</head>

<body>

<?php

imagejpeg($image);

?>

</body>

</html>

 

 

Here is the error I got:

 

Warning: Cannot modify header information - headers already sent by (output started at /.reducto/web/apps/vtfileman/dxs129/phptest.php:2) in /.reducto/web/apps/vtfileman/dxs129/phptest.php on line 3

Opened image

Warning: imagejpeg(): supplied argument is not a valid Image resource in /.reducto/web/apps/vtfileman/dxs129/phptest.php on line 23

 

 

The code is so simple. I really posted EVERYTHING in the page. Can someone please tell me what Im doing wrong? Oh, I have the page on a server provided by my school. Ive never had a problem with PHP pages through them before. SOME PLEASE HELP! :)

 

Link to comment
Share on other sites

<?php
header('Content-Type: image/jpeg');
$image = open_image($image);
if ($image === false) { die ('Unable to open image'); }
// ... Do some manipulation here ...
// Send header
// Display image

function open_image ($file) {
        $im = @imagecreatefromjpeg('Spiderman_3.jpg');
if ($im === false) {
        die ('Unable to open image');
}
echo 'Opened image';
}
?>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<?php
imagejpeg($image);
?>
</body>
</html>

Link to comment
Share on other sites

You cannot output image date in the middle (start or end) of a html web page.

 

Each image on a web page requires an <img src="url" alt=""> tag - http://w3schools.com/html/html_images.asp

 

To output an image using php, the url in src="url" is the url of your php script, something like <img src="image.php" alt="">

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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