Forums


Marketplace (en)

Forum for Marketplace, a Joomla! 1.0 classified ads component. Posts in english language.
Public write access is disabled. Please login or register
Last post
Forums  » Marketplace (en)  » auto image resizing
simondavidson

simondavidson
4 posts
---
Location:
n.a.
09.01.2010 16:30

auto image resizing

is 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

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------->




lateralus

lateralus
14 posts
---
Location:
n.a.
30.05.2010 16:36
Re: auto image resizing
Hi,

it sounds like a very nice trick ;) ;)
but it's not workin with me...

I have GD installed so it should not be the problem!
I have no other pb at all with MP 1.4.6

Any help ??

Thanks

ludo




Forums  » Marketplace (en)  » auto image resizing
Discussions v1.1
(c) 2010 Codingfish

Login