Jump to content

Problem with imagejpeg


emancipator

Recommended Posts

I am trying to write a very simple image displaying program, I am using HostMonster.

 

The problem being: when i remove the function (ie. move everything outside of the function), everything works fine but when I put everything into the function (ie. code below) and execute it in the body, nothing gets displayed except the link (url).

 

Any idea?

 

Here is the code:

<?php
header('Content-type: image/jpeg');

function image(){
	$filename = 'TEST.JPG';
	$image = imagecreatefromjpeg($filename);
	imagejpeg($image,null,100);
}
?>

<html>
<body>
<?php
image();
?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/83102-problem-with-imagejpeg/
Share on other sites

Thanks for the reply.

 

I still don't quite understand the difference between image operation and say echoing something, and how do I pass function parameters if I can't really "call" the function in html.

 

I guess my question remains how do I execute a function that does image manipulation (like create a thumb size picture page based on a list of pictures).

 

Sorry for being so noob-ish, and thanks in advance for replying.

You need a "thumb.php" script that creates a thumnail size image of the file passed to it

 

<?php
$picToResize = $_GET['pic']

$src = imagecreatefromjpeg($picToResize);

// resize code here

imagejpeg ($thumbImage);
imagedestroy($src);
imagedestroy($thumb):
?>

 

In your main page you then output a series of img tags to output the thumbnail images, passing the file to process in the query string.

 

EG

<?php
$images = array ('a.jpg', 'b.jpg', 'c.jpg');

foreach ($images as $picture)
{
     echo "<img src='thumb.php?pic=$picture'>";
}

 

If it is displaying literally "<img src='thumb.php?pic=$picture'>", just take the $picture out of the string quote, like this:

 

echo "<img src='thumb.php?pic=".$picture." '>";

 

Although I could be COMPLETELY missing the point but I had the same problem sometimes with keeping the variable within the echo'd string.

 

And btw, I am not exactly an expert on php but isn't image a keyword?  So using image as a function name wouldn't work.  Change the name to createImage or something...  Although again, I could be completely missing the point.  hehe... :)

 

 

Archived

This topic is now archived and is closed to further replies.

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