Resample a JPG image without writing to disk
Posted: Fri Jun 18, 2004 6:15 am
Now I use this code to resample a JPG image.
And afterwards add it to a database.
Is it possible to do this without writing to the hard disk?
Thanks,
Waldo Monster
And afterwards add it to a database.
Is it possible to do this without writing to the hard disk?
Thanks,
Waldo Monster
Code: Select all
<?php
// +-------------------------------------------------------------------------+
// | Resample Image |
// +-------------------------------------------------------------------------+
Function ResampleImage($source_image, $destination_image, $size)
{
$src_image = imageCreateFromJpeg($source_image);
$dst_image = imageCreateTrueColor($size, $size);
imageCopyResampled($dst_image, $src_image, 0, 0, 0, 0, $size, $size, imageSX($src_image), imageSY($src_image));
imageJpeg($dst_image, $destination_image, 90);
imageDestroy($src_image);
imageDestroy($dst_image);
}
$source_image = 'D:/test.jpg';
$temp_image = 'D:/temp.jpg';
ResampleImage($source_image, $temp_image, 200);
$image = file_get_contents($temp_image);
unlink($temp_image);
//Add $image to a database
?>