...

View Full Version : out an image after imagecopyresampled



kamkam
08-22-2009, 09:24 AM
Hi;

I am trying to output an image after imagecopyresampled, but it doesn't display any image on browser, could you tell me why, please.



it just out some thing like following:

����JFIF��


My original image is 36KB and 900*900
and i want them become to 18kb and 100&100



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=utf-8">
</head>
<body>

<?php
function resizeImage($originalImage,$toWidth,$toHeight){

// Get the original geometry and calculate scales
list($width, $height) = getimagesize($originalImage);
$xscale=$width/$toWidth;
$yscale=$height/$toHeight;

// Recalculate new size with default ratio
if ($yscale>$xscale){
$new_width = round($width * (1/$yscale));
$new_height = round($height * (1/$yscale));
}
else {
$new_width = round($width * (1/$xscale));
$new_height = round($height * (1/$xscale));
}

// Resize the original image
$imageResized = imagecreatetruecolor($new_width, $new_height);
$imageTmp = imagecreatefromjpeg ($originalImage);
imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

return $imageResized;
}
?>

<?php
$image= resizeImage("upload/testimage.jpg",200,200);
imagejpeg($image, null, 100);

//$info = getimagesize("upload/testimage.jpg");
//print_r($image);
?>

</body>
</html>

Mwnciau
08-22-2009, 02:31 PM
When PHP makes an image then outputs it, it generates a seperate file from any HTML. Remove all HTML coding and spaces on that page and add this somewhere in the PHP coding before any output. It changes the page type to an image:


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

kamkam
08-23-2009, 12:03 AM
but it still does not display the image, after i added the header on it, just shows a square, and there is a cross inside the square.

and also if write like <img src="upload/testimage.jpg">, it give me the same result as above, but if i write <img src="upload/testimage.jpg"> to another page, it will display the image.






<?php
header('Content-type:image/jpeg');
?>
<?php
function resizeImage($originalImage,$toWidth,$toHeight){

// Get the original geometry and calculate scales
list($width, $height) = getimagesize($originalImage);
$xscale=$width/$toWidth;
$yscale=$height/$toHeight;

// Recalculate new size with default ratio
if ($yscale>$xscale){
$new_width = round($width * (1/$yscale));
$new_height = round($height * (1/$yscale));
}
else {
$new_width = round($width * (1/$xscale));
$new_height = round($height * (1/$xscale));
}

// Resize the original image
$imageResized = imagecreatetruecolor($new_width, $new_height);
$imageTmp = imagecreatefromjpeg ($originalImage);
imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

return $imageResized;
}
?>

<?php
$image= resizeImage("upload/testimage.jpg",200,200);
imagejpeg($image, null, 100);

//$info = getimagesize("upload/testimage.jpg");
//print_r($image);
?>

kamkam
08-23-2009, 12:46 AM
and if i change as following, it display nothing, even the litter square and cross disapear away


<?php
$image= resizeImage("upload/testimage.jpg",200,200);
imagejpeg($image, 'upload/testimage.jpg', 100);


?>

Element
08-23-2009, 06:52 AM
<?php

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

function resizeImage($originalImage,$toWidth,$toHeight){

// Get the original geometry and calculate scales
list($width, $height) = getimagesize($originalImage);
$xscale=$width/$toWidth;
$yscale=$height/$toHeight;

// Recalculate new size with default ratio
if ($yscale>$xscale){
$new_width = round($width * (1/$yscale));
$new_height = round($height * (1/$yscale));
}
else {
$new_width = round($width * (1/$xscale));
$new_height = round($height * (1/$xscale));
}

// Resize the original image
$imageResized = imagecreatetruecolor($new_width, $new_height);
$imageTmp = imagecreatefromjpeg ($originalImage);
imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

return $imageResized;
}


$image= resizeImage("upload/testimage.jpg",200,200);
imagejpeg($image, null, 100);

//$info = getimagesize("upload/testimage.jpg");
//print_r($image);

?>

No spaces, pure PHP block.

kamkam
08-23-2009, 08:00 AM
an image comes out now, but it is strange that the image is not the one i want.

it comes out an image with some text of the "A Simple Text String" and the background color is black.

But in my folder upload, the image testimage.jpg is a buillding

kamkam
08-23-2009, 08:02 AM
an image comes out now, but it is strange that the image is not the one i want.
it comes out an image with some text of the "A Simple Text String" and the background color is black.

But in my folder upload, the image testimage.jpg is a buillding

Element
08-24-2009, 02:12 AM
You should take a look at my Dynamic Image Resizing (http://codingforums.com/showthread.php?t=72029) in the snippet section. Will solve all your problems. ;)

randy1
08-24-2009, 11:15 AM
You can generate it
Cheap Web Hosting (http://www.cheapwebhostingseller.com/) || Web Hosting (http://www.businesswebhostingplans.com/)
by using any HTML.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum