After a bit of investigation I decided to use Carrierwave and mini_magick on my new rail3 app.
I\'ve set it up and it works perfectly. However I have a one question. I\
Disadvantage of calculating Image height
/ width
using RMagick
or MiniMagick
in run time:
FYI You can also calculate the Image
Height
,Width
after the Image is fully loaded by using theload
event associated with thetag with the help of jQuery.
For Example:
$(document).ready(function(){
var $image = $('.fixed-frame img');
$image.load(function(){
rePositionLogo($image);
});
if($image.prop('complete')){
rePositionLogo($image);
}
});
function rePositionLogo($image){
var height = $image.height();
var width = $image.width();
if (width > height) {
$image.parents('.header').addClass('landscape');
var marginTop = (105 - $image.height())/2;
$image.css('margin-top', marginTop + 'px')
}else{
$image.parents('.header').addClass('portrait');
}
}
Be careful, because load()
will not trigger when an image is already loaded. This can happens easily when an image is in the user's browser cache
.
You can check if an image is already loaded using $('#myImage').prop('complete')
, which returns true
when an image is loaded.