mbony
08-01-2004, 03:37 PM
I am looking for an image uploader for public use that can resize in the case that an image is larger than the requirements given (ex. 800x600). I need it in php too.
This would be good for users who don't have graphic editing tools, but still want to have an image to use on their site/blog/etc.
Suggestions?
Thanks!
UH-Matt
08-01-2004, 03:39 PM
Wouldnt be difficult to adjust an existing uploader script and use Imagemagick to adjust the images to the correct size.
blue27
08-01-2004, 03:52 PM
I think Coppermine will let you set the size parameters for uploaded images.
GideonX
08-01-2004, 04:16 PM
If you are willing to pay, try Photopost.
akashik
08-01-2004, 06:18 PM
http://www.4homepages.de/
This one does it just fine.
RackNine
08-01-2004, 07:58 PM
Here's a script to run a bicubic resample through GDlib. It'll return your result on-the-fly which can thereafter be done with as you wish:
(note it's modified from original work provided to the public domain, see credits in function below)
<?
/*
Function: imageResize (image_functions.php)
Require: GDlib 1.6 or greater
Description:
Rather than poor quality image changes provided by PHP this
function allows for Bicubic resampling of image to produce
a much higher-quality result. Based on original
ImageCopyResampleBicubic function provided below.
--- usage ---
imageResize(&$src, $x, $y)
takes original GD image source $src and resizes to $x, $y
pixels (width, height). Return is GD image resource
of resampled size.
NOTE: Don't forget to imagedestroy() resources when no longer needed!
If using GDlib < 2.0 change ImageCreateTrueColor to ImageCreate
*/
function imageResize (&$src, $x, $y) {
$dst = ImageCreateTrueColor ($x, $y);
#########################
ImagePaletteCopy ($dst,$src);
#########################
$scX = (imagesx ($src) - 1) / $x;
$scY = (imagesy ($src) - 1) / $y;
$scX2 = intval($scX / 2);
$scY2 = intval($scY / 2);
for ($j = 0; $j < ($y); $j++) {
$sY = intval($j * $scY);
$y13 = $sY + $scY2;
for ($i = 0; $i < ($x); $i++) {
$sX = intval($i * $scX);
$x34 = $sX + $scX2;
$c1 = ImageColorsForIndex ($src, ImageColorAt ($src, $sX, $y13));
$c2 = ImageColorsForIndex ($src, ImageColorAt ($src, $sX, $sY));
$c3 = ImageColorsForIndex ($src, ImageColorAt ($src, $x34, $y13));
$c4 = ImageColorsForIndex ($src, ImageColorAt ($src, $x34, $sY));
$r = ($c1['red'] + $c2['red'] + $c3['red'] + $c4['red'])/4;
$g = ($c1['green'] + $c2['green'] + $c3['green'] + $c4['green'])/4;
$b = ($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue'])/4;
ImageSetPixel ($dst, $i, $j, ImageColorClosest ($dst, $r, $g, $b));
}
}
return ($dst);
}
function ImageCopyResampleBicubic (&$dst_img, &$src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) {
/*
port to PHP by John Jensen July 10 2001 (updated 4/21/02) -- original code (in C, for the PHP GD Module) by jernberg@fairytale.se
*/
$palsize = ImageColorsTotal ($src_img);
for ($i = 0; $i < $palsize; $i++) { // get palette.
$colors = ImageColorsForIndex ($src_img, $i);
ImageColorAllocate ($dst_img, $colors['red'], $colors['green'], $colors['blue']);
}
$scaleX = ($src_w - 1) / $dst_w;
$scaleY = ($src_h - 1) / $dst_h;
$scaleX2 = (int) ($scaleX / 2);
$scaleY2 = (int) ($scaleY / 2);
for ($j = $src_y; $j < $dst_h; $j++) {
$sY = (int) ($j * $scaleY);
$y13 = $sY + $scaleY2;
for ($i = $src_x; $i < $dst_w; $i++) {
$sX = (int) ($i * $scaleX);
$x34 = $sX + $scaleX2;
$color1 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $sX, $y13));
$color2 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $sX, $sY));
$color3 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $x34, $y13));
$color4 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $x34, $sY));
$red = ($color1['red'] + $color2['red'] + $color3['red'] + $color4['red']) / 4;
$green = ($color1['green'] + $color2['green'] + $color3['green'] + $color4['green']) / 4;
$blue = ($color1['blue'] + $color2['blue'] + $color3['blue'] + $color4['blue']) / 4;
ImageSetPixel ($dst_img, $i + $dst_x - $src_x, $j + $dst_y - $src_y, ImageColorClosest ($dst_img, $red, $green, $blue));
}
}
}
?>