Avatar resizing

16 years 10 months ago #38222 by wingflap
Avatar resizing was created by wingflap
Hope I'm posting this in the right area.

I'm using CB 1.0.2 and Joomla 1.0.12 and GD2 (offered on my host). I set the thumbnail width and height to 150 and 150 respectively.

I assume the image handling is done in imgToolbox.class.php. After the function resizeImage checks the actual width and height of the image against $maxheight and $maxwidth, a resize for thumbnail occurs.

If the dimensions of the image being uploaded (in this case an avatar) have a width < the thumbnail width and a height < the thumbnail height, shouldn't the image file be simply copied to a file with 'tn' prepended to the name?

The reason that I ask is that animated gif avatars that I upload become static because of the image conversion. Would the correct fix for this to be to put a size comparison against the thumb width and height right before the resizing for thumbnails. If the size is an acceptable thumbnail size, then simply do a file copy instead of a call to resizeImage?

Also, I noticed defaults set to width=86 and height=60 for thumbnails. I've seen other threads about avatar images being too large and messing up some module and/or plugin formatting. Are these default values the recommended values?

Thanks in advance and please forgive my noobie-ness.

I am the Wingflap. Goo Goo G'Joob!<br>

How comfortable are you? Visit www.comfortometer.com

Please Log in to join the conversation.

16 years 10 months ago #38230 by nant
Replied by nant on topic Re:Avatar resizing
wingflap wrote:

Hope I'm posting this in the right area.

I'm using CB 1.0.2 and Joomla 1.0.12 and GD2 (offered on my host). I set the thumbnail width and height to 150 and 150 respectively.

I assume the image handling is done in imgToolbox.class.php. After the function resizeImage checks the actual width and height of the image against $maxheight and $maxwidth, a resize for thumbnail occurs.

If the dimensions of the image being uploaded (in this case an avatar) have a width < the thumbnail width and a height < the thumbnail height, shouldn't the image file be simply copied to a file with 'tn' prepended to the name?

The reason that I ask is that animated gif avatars that I upload become static because of the image conversion. Would the correct fix for this to be to put a size comparison against the thumb width and height right before the resizing for thumbnails. If the size is an acceptable thumbnail size, then simply do a file copy instead of a call to resizeImage?

Also, I noticed defaults set to width=86 and height=60 for thumbnails. I've seen other threads about avatar images being too large and messing up some module and/or plugin formatting. Are these default values the recommended values?

Thanks in advance and please forgive my noobie-ness.


Yup - you are correct - no resizing should take place if the uploaded file has the proper dimensions.

I am currently working on this part of CB for the next release and will be taking a closer look at how things actually work in order to add some extra functionality.
Potential candidate functions include exact measurements resizing (combo resize and crop), watermarking, etc.

Please Log in to join the conversation.

16 years 10 months ago #38300 by wingflap
Replied by wingflap on topic Re:Avatar resizing
Made a quick pass at this. The resize function determines aspect ratio and then, uses the appropriate ratio to determine a new height and new width:

[code:1] $nWidth = floor($width*$ratio);
$nHeight = floor($height*$ratio);[/code:1]

from within the resize function, right before the switch csae on conversion methods, you could simple check if:

I am the Wingflap. Goo Goo G'Joob!<br>

How comfortable are you? Visit www.comfortometer.com

Please Log in to join the conversation.

16 years 10 months ago #38303 by wingflap
Replied by wingflap on topic Re:Avatar resizing
Oops. hit enter by mistake. One more time...

Made a quick pass at this. The resize function determines aspect ratio and then, uses the appropriate ratio to determine a new height and new width:

[code:1]
$nWidth = floor($width*$ratio);
$nHeight = floor($height*$ratio);
[/code:1]

from within the resize function, right before the switch csae on conversion methods, you could simple check if:
$nWidth=$width and $nHeight=$height

or you could check simply if $ratio=1.

If either is the case, you simply want to do a copy for the filename to the thumbnail filename.

But...

The function is a resize function and I didn't think that copyfile logic belonged in the resize function.

So what I changed was the logic calling the resize function (around line 200 in administrator/components/com_profiler/imgToolbox.class.php) from:

[code:1]
// resize to thumbnail...
if(!$this->resizeImage($file, $thumbfile, $this->_thumbwidth, $this->_thumbheight, $filename)){
$this->raiseError("Error: resizing thumbnail image failed."«»);
return false;
}
[/code:1]

To:

[code:1]
// resize to thumbnail...
// resize thumb fix - check if the image file is bigger than allowed thumbnail
if($imginfo[0] > $this->_thumbwidth || $imginfo[1] > $this->_maxheight){
if(!$this->resizeImage($file, $thumbfile, $this->_thumbwidth, $this->_thumbheight, $filename)){
$this->raiseError("Error: resizing thumbnail image failed."«»);
return false;
}
// resize thumb fix - else, just copy the file to the thumbnail file
} else {
if (!@copy($file, $thumbfile)){
// some error occured while copying the file to the thumbnail file
$this->raiseError("Error occurred copying the uploaded file to the thumbnail."«»);
return false;
}
}
[/code:1]

I am the Wingflap. Goo Goo G'Joob!<br>

How comfortable are you? Visit www.comfortometer.com

Please Log in to join the conversation.

16 years 10 months ago #38304 by wingflap
Replied by wingflap on topic Re:Avatar resizing
Oops. hit enter by mistake. One more time...

Made a quick pass at this. The resize function determines aspect ratio and then, uses the appropriate ratio to determine a new height and new width:

[code:1]
$nWidth = floor($width*$ratio);
$nHeight = floor($height*$ratio);
[/code:1]

from within the resize function, right before the switch csae on conversion methods, you could simple check if:
$nWidth=$width and $nHeight=$height

or you could check simply if $ratio=1.

If either is the case, you simply want to do a copy for the filename to the thumbnail filename.

But...

The function is a resize function and I didn't think that copyfile logic belonged in the resize function.

So what I changed was the logic calling the resize function (around line 200 in administrator/components/com_profiler/imgToolbox.class.php) from:

[code:1]
// resize to thumbnail...
if(!$this->resizeImage($file, $thumbfile, $this->_thumbwidth, $this->_thumbheight, $filename)){
$this->raiseError("Error: resizing thumbnail image failed."«»);
return false;
}
[/code:1]

To:

[code:1]
// resize to thumbnail...
// resize thumb fix - check if the image file is bigger than allowed thumbnail
if($imginfo[0] > $this->_thumbwidth || $imginfo[1] > $this->_maxheight){
if(!$this->resizeImage($file, $thumbfile, $this->_thumbwidth, $this->_thumbheight, $filename)){
$this->raiseError("Error: resizing thumbnail image failed."«»);
return false;
}
// resize thumb fix - else, just copy the file to the thumbnail file
} else {
if (!@copy($file, $thumbfile)){
// some error occured while copying the file to the thumbnail file
$this->raiseError("Error occurred copying the uploaded file to the thumbnail."«»);
return false;
}
}
[/code:1]

I am the Wingflap. Goo Goo G'Joob!<br>

How comfortable are you? Visit www.comfortometer.com

Please Log in to join the conversation.

16 years 10 months ago #38305 by wingflap
Replied by wingflap on topic Re:Avatar resizing
I have to learn to stop using my back button.:blush:

I am the Wingflap. Goo Goo G'Joob!<br>

How comfortable are you? Visit www.comfortometer.com

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.346 seconds

Facebook Twitter LinkedIn