...

View Full Version : imagecopyresampled SOLVED!!



chadconger
07-25-2006, 02:06 AM
My goal is to resize a picture that has been uploaded so I researched how to do that and found my code at http://us2.php.net/manual/en/function.imagecopyresampled.php it is example two. I uploaded a picture named test.jpg to the same directory as the page and I get this error

Warning: Cannot modify header information - headers already sent by (output started at /home/istockfi/public_html/spurtstudios/test.php:2) in /home/istockfi/public_html/spurtstudios/test.php on line 12

followed by a lot of charaters that make no sense to me. You can view the acual page at http://www.spurtstudios.com/test.php

You can view my GD info at http://www.spurtstudios.com/gd.php
Can anyone point me in the right direction?

I have tried several other scripts like this one with no luck so I think it may be a a problem with my host but I don't know what I should do or what to ask them to do.

Here is my code


<?php

// The file
$filename = 'test.jpg';

// Set a maximum height and width
$width = 200;
$height = 200;

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

// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);

if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}

// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

// Output
imagejpeg($image_p, null, 100);
?>

Fumigator
07-25-2006, 02:32 AM
How are you executing test.php? You don't execute it like a normal PHP file; you insert it in an img tag like this:


<img src="test.php" />

chadconger
07-25-2006, 02:38 AM
How are you executing test.php? You don't execute it like a normal PHP file; you insert it in an img tag like this:


<img src="test.php" />


I tried this at http://www.spurtstudios.com/test2.html but Ijust got a little box with an x in it. Any other suggestions?

Fumigator
07-25-2006, 03:05 AM
I really don't know... your code worked for me (I just tried it).

Maybe try a valid HTML page to test it in.

chadconger
07-25-2006, 03:31 AM
I tried another code that works for me but it only resizes by a percentage.
You can view it here http://spurtstudios.com/test3.php
I want to make it have a max height of 100px and stay proportionate though.
Any way to
Here it is


<?php
// The file
$filename = 'test.jpg';
$percent = 0.1;

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

// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;

// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Output
imagejpeg($image_p, null, 100);
?>

litebearer
07-25-2006, 03:41 AM
Might look here...

http://www.nstoia.com/toh/technical/imageresize/index.php

it allows you to set max height and/or width, while keeping the result proportional

Lite...

chadconger
07-25-2006, 03:47 AM
I fixed it myself somehow.
you can see it hear. http://spurtstudios.com/test5.php
I'm not sure how I did it but hears the code



<?php
// The file
$filename = 'test.jpg';

// Set a maximum height and width
$width = 200;
$height = 200;
// Content type
header('Content-type: image/jpeg');

// Get new dimensions
list($widthOrig, $heightOrig) = getimagesize($filename);

if ($widthOrig < $heightOrig) {
$width = ($height / $heightOrig) * $widthOrig;
} else {
$height = ($width / $widthOrig) * $heightOrig;
}


// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $widthOrig, $heightOrig);

// Output
imagejpeg($image_p, null, 100);
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum