|
simondavidson
4 posts Location: n.a. |
09.01.2010 16:30auto image resizingis it possible to use some coding to automatically resize images that are to big during upload, example, customer tries to ad an image that is 2mb in size and the system is set to 0.2mb, if the customer does this now, their image does not upload, so auto resizing would be great, is this possible
|
|
cro24all
21 posts Location: n.a. |
23.01.2010 11:19 Re: auto image resizing size and format photography is a big problem, but without coding does not help.
In theory the script that creates a thumb should be able to create photo smaller dimensions, but how to implement he he...
code--->write_ad.php
...
$af_dir_ads = $mosConfig_absolute_path."/components/com_marketplace/images/entries/";
// check imagesize
$database->setQuery( "SELECT max_image_size FROM #__marketplace_config");
$max_image_size = $database->loadResult();
$image_too_big = 0;
// loop over configured # of images and check size
for ( $i = 1; $i $max_image_size) {
$image_too_big = 1;
}
}
}
if ( $image_too_big == 1) { // image is too big -> display message
echo "";
echo JOO_IMAGETOOBIG;
echo "";
echo "";
echo "";
}
else { // images are ok
$af_size = GetImageSize ($_FILES[$image]['tmp_name'], $af_info);
switch ($af_size[2]) {
case 1 : {
$thispicext = 'gif';
break;
}
case 2 : {
$thispicext = 'jpg';
break;
}
case 3 : {
$thispicext = 'png';
break;
}
}
...
// create thumbnail
switch ($af_size[2]) {
case 1 : $src = ImageCreateFromGif( $af_dir_ads.$adid.$itrail.".".$thispicext); break;
case 2 : $src = ImageCreateFromJpeg( $af_dir_ads.$adid.$itrail.".".$thispicext); break;
case 3 : $src = ImageCreateFromPng( $af_dir_ads.$adid.$itrail.".".$thispicext); break;
}
$width_before = ImageSx( $src);
$height_before = ImageSy( $src);
if ( $width_before >= $height_before) {
$width_new = min(100, $width_before);
$scale = $width_before / $height_before;
$height_new = round( $width_new / $scale);
}
else {
$height_new = min(75, $height_before);
$scale = $height_before / $width_before;
$width_new = round( $height_new / $scale);
}
$dst = ImageCreateTrueColor( $width_new, $height_new);
// GD Lib 2
ImageCopyResampled( $dst, $src, 0, 0, 0, 0, $width_new,
$height_new, $width_before, $height_before);
$height_new, $width_before, $height_before);
switch ($af_size[2]) {
case 1 : ImageGIF( $dst, $af_dir_ads.$adid.$itrail."_t.".$thispicext); break;
case 2 : ImageJPEG( $dst, $af_dir_ads.$adid.$itrail."_t.".$thispicext); break;
case 3 : ImagePNG( $dst, $af_dir_ads.$adid.$itrail."_t.".$thispicext); break;
}
imagedestroy( $dst);
imagedestroy( $src);
code------->
|