Square User Avatar

16 years 11 months ago #37272 by tomsawyer1234
Replied by tomsawyer1234 on topic Re:Square User Avatar
hermana_v,

I have setup the code you propose for my CB/Joomla installation but I have notice that the image get resized to "$thumb_size=100; " for both main profil image and small thumbnails (used for the connexions" tab for example).

Do you have the same behaviour?


concerning the polaroid iamge, I have look at it but I didn't manage to integrate it, but it should be easy for someone with god php knowledge.

regards

Florian

Please Log in to join the conversation.

16 years 11 months ago #37328 by hermana_v
Replied by hermana_v on topic Re:Square User Avatar
Yes, Florian, i had the same issue. Now it's fixed and with this code you'll have thumbnails with dimensions you specify in CB backend(maximum, they say) and profile images with maximum dimensions you also specify in that backend.

function resizeImageGD2($src_file, $dest_file, $destWidth,$destHeight){
$imginfo = getimagesize($src_file);
if ($imginfo == null) {
$this->raiseError("Error: Unable to execute getimagesize function");
return false;
}
$width=$imginfo[0];
$height=$imginfo[1];


if($width> $height) {
$x = ceil(($width - $height) / 2 );
$width = $height;
} elseif($height> $width) {
$y = ceil(($height - $width) / 2);
$height = $width;
}

$destWidth = $destHeight;
$destHeight = $destWidth;

// GD can only handle JPG & PNG images
if ($imginfo[2] != 2 && $imginfo[2] != 3 && ($imginfo[2] == 1 && !function_exists(imagecreatefromgif))){
$this->raiseError("Error: GD2 Unable to create image from imagetype function");
return false;
}
if ($imginfo[2] == 2)
$src_img = imagecreatefromjpeg($src_file);
elseif ($imginfo[2] == 1)
$src_img = imagecreatefromgif($src_file);
else
$src_img = imagecreatefrompng($src_file);
if (!$src_img) {
$this->raiseError("Error: GD2 Unable to create image from imagetype function");
return false;
}
$dst_img = imagecreatetruecolor($destWidth, $destHeight);
imagecopyresampled($dst_img, $src_img, 0, 0, $x, $y, $destWidth, $destHeight, $width, $height);
if ($imginfo[2] == 2) {
imagejpeg($dst_img, $dest_file, $this->_JPEGquality);
} elseif ($imginfo[2] == 1) {
if(function_exists('imagegif')) {
imagegif($dst_img, $dest_file);
} else {
$this->raiseError("Error: GIF Uploads are not supported by this version of GD");
return false;
}
} else {
imagepng($dst_img, $dest_file);
}
imagedestroy($src_img);
imagedestroy($dst_img);
return true;
}


But there's a small issue: profile image dimensions are in some sort unpredictable. For example, i have 2 different images with the same original dimensions, but in the end i receive profile images with different size, one cropped to 250x250 as i specified in backend, and one to 188x188 which i didn't expect.

maybe it relates to cropping behavior which is in some way centered.

Very glad you appreciate my work!

Cheers,
Tanja

Please Log in to join the conversation.

16 years 11 months ago #37334 by tomsawyer1234
Replied by tomsawyer1234 on topic Re:Square User Avatar
Tks!

I have also notice the small bug but it is acceptable. The function could be optimized. I someone good at PHP could have a look at it!

I think this function should be a standard in CB!:woohoo:

Please Log in to join the conversation.

16 years 10 months ago #39553 by wired
Replied by wired on topic Re:Square User Avatar
Awesome guys!! But can this be adapted to first resize then crop from the center like fredfred.net/skriker/index.php/iimage-gallery ?

crop="true" crop_center="true" max_side="100" quality="95"


That way it's just not a simple crop. Looks way better.

Please Log in to join the conversation.

16 years 10 months ago #39554 by wired
Replied by wired on topic Re:Square User Avatar
Wow, got it to work by just throwing that in there!

Please Log in to join the conversation.

16 years 10 months ago #39604 by Dionysus
Replied by Dionysus on topic Re:Square User Avatar
Can you tell me where to add in this code?

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.521 seconds

Facebook Twitter LinkedIn