Hello,
Do you know a mod working for 3.0.11 which can resize automatically avatar when a user upload one?
Thanks in advance
Code: Select all
function resize_image($file, $w, $h, $crop=FALSE)
{
list($width, $height) = getimagesize($file);
$r = $width / $height;
if ($crop) {
if ($width > $height) {
$width = ceil($width-($width*abs($r-$w/$h)));
} else {
$height = ceil($height-($height*abs($r-$w/$h)));
}
$newwidth = $w;
$newheight = $h;
} else {
if ($w/$h > $r) {
$newwidth = $h*$r;
$newheight = $h;
} else {
$newheight = $w/$r;
$newwidth = $w;
}
}
if($this->extension == "jpg") $src = imagecreatefromjpeg($file);
if($this->extension == "png") $src = imagecreatefrompng($file);
$dst = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
if($this->extension == "jpg") imagejpeg($dst,$file);
if($this->extension == "png") imagepng($dst,$file);
}
Code: Select all
$this->resize_image($this->filename,$this->upload->max_width,$this->upload->max_height);