I created a function (appears below) that crops a JPG and outputs it on the
fly. However Apache crashes when I use the function. Unfortunately, Apache
does not put an error message in the logs.
I'm running it on a Windows2000 machine with Apache 1.3.20 and PHP 4.0.6
(installed via EasyPHP 1.5.0.0).
I've isolated the problem to be the ImageCopy() function, I'm sure of this.
If I use ImageCopyMerge() instead (with pct = 100), it works albeit with
varying results.
Has anyone else encountered this? Does anyone know how to fix it?
---snip---
function ImageCropJPEG( $src_file, $dst_file, $dst_width, $dst_height,
$quality = '100', $crop_type = 'r' ) {
// Must be a valid file
if ( is_file( $src_file ) ) {
// Get image dimensions
list( $src_width, $src_height, $src_type ) = @GetImageSize(
$src_file );
// Must be a valid JPEG
if ( is_set( $src_width ) && is_set( $src_height ) && $src_type ==
2 ) {
// Generate crop coords
switch ( $crop_type ) {
// Centered crop coords
case 'c':
$src_x = max( 1, floor( ( $src_width - $dst_width ) /
2 ) );
$src_y = max( 1, floor( ( $src_height - $dst_height ) /
2 ) );
break;
// Random crop coords
case 'r':
default:
$src_x = mt_rand( 0, max( 1, $src_width - $dst_width -
1 ) );
$src_y = mt_rand( 0, max( 1, $src_height -
$dst_height - 1 ) );
break;
}
// Create resources pointers for source and destination images
$src_image = ImageCreateFromJPEG( $src_file );
$dst_image = ImageCreate( $dst_width, $dst_height );
// Copy cropped portion of source image to destination image
ImageCopy( $dst_image, $src_image, 0, 0, $src_x, $src_y,
$dst_width, $dst_height );
# ImageCopyMerge( $dst_image, $src_image, 0, 0, $src_x, $src_y,
$dst_width, $dst_height, 100 ); // testing...
// Output to STDOUT
if ( empty( $dst_file ) ) {
header( 'Content-type: image/jpeg' );
}
// Output image
ImageJPEG( $dst_image, $dst_file, $quality );
// Free any memory associated the source and destination images
ImageDestroy( $src_image );
ImageDestroy( $dst_image );
}
}
return( TRUE );
}
---snip---
Forgive me if this has been asked before. I searched the archives but
couldn't find the answer.
TIA!
geoff.catlin
programmer#Q15439
-----------------------
http://www.3rdkynd.com
http://www.urthling.com
3rdkynd :: From the electricity of the edge to the subtlety
of the sublime, we've got what you've been looking for.
e :: [EMAIL PROTECTED]
p :: 315.685.3415
f :: 315.685.5159