My code is below. The commented out echo prior to calling the function crashes the action if I uncomment it. Since I will be inserting a number of clipped images onto the page, there will, of necessity be content sent prior to calling the function.
I'm sure there is something obvious here, but I am not seeing it.
Thanks,
--Kenoli
Code: Select all
<?php
function clip_image($filename) {
// Get width & height of image
list($current_width, $current_height) = getimagesize($filename);
//echo "Width = $current_width, Height = $current_height";
// Set final crop size
$crop_width = 150; $crop_height = 150;
// Calculate origin of crop
$origin_left = ($current_width - $crop_width)/2;
$origin_top = ($current_height - $crop_height)/2;
//echo "<br/><br/>Left origin = $origin_left";
//echo "<br/><br/>Top origin = $origin_top";
// Create the crop template image and place image in a function
$src = imagecreatefromjpeg($filename);
$dest = imagecreatetruecolor(150, 150);
// Clip the image
imagecopy($dest, $src, 0, 0, $origin_left, $origin_top, $current_width, $current_height);
// Output image
header('Content-Type: image/jpeg');
$dest = imagejpeg($dest, $stuff);
// Clear memory
imagedestroy($dest);
imagedestroy($src);
}
//echo 'This is the beginning'; // This line if uncommented prevents the display of the image
$filename = 'images/arrow.jpg';
$stuff = clip_image($filename);
echo "<img src = \"$stuff\" />";
?>