wtf? I cannot figure out imagecopyresampled
Posted: Mon Jan 28, 2008 7:09 pm
I have been working on figuring out exactly how imagecopyresampled works for the last like 4 hours. I cannot figure it out. What do all of the parameters do? I just CANT seem to get it to do anything I want. No matter what I try I end up with black space on one side of the image. WTF?
I feel like an idiot. Maybe it's just really late in the day and I need sleep. 
Code: Select all
<?php
$imagesrc_location = 'C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\castle.jpg';
$imagedst_location = 'C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\castle_resampled.jpg';
// Get new sizes
list($srcwidth, $srcheight) = getimagesize($imagesrc_location);
list($dstwidth, $dstheight) = array($srcwidth, ($srcheight));
$imagedst = imagecreatetruecolor($dstwidth, $dstheight); // I think some of my problems stem from here... I dont know if I'm creating the right dimensions for the file
$imagesrc = imagecreatefromjpeg($imagesrc_location);
if (imagecopyresized($imagedst, $imagesrc, 0, 0, 0, 0, $dstwidth, $dstheight, $srcwidth, $srcheight)) { // what do all those zeroes do? I tried figuring it out, but it just doesn't make sense to me
// Output image
header('Content-type: image/jpeg');
imagejpeg($imagedst);
} else {
echo "Could not resize file";
}