mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-05-24 16:28:40 -04:00
item pics are now resized and cached server side
This commit is contained in:
@@ -67,6 +67,34 @@ class Items extends Secure_area implements iData_controller
|
||||
echo $data_rows;
|
||||
$this->_remove_duplicate_cookies();
|
||||
}
|
||||
|
||||
function pic_thumb($pic_id)
|
||||
{
|
||||
$this->load->helper('file');
|
||||
$this->load->library('image_lib');
|
||||
$base_path = "uploads/item_pics/" . $pic_id ;
|
||||
$images = glob ($base_path. "*");
|
||||
if (sizeof($images) > 0)
|
||||
{
|
||||
$image_path = $images[0];
|
||||
$ext = pathinfo($image_path, PATHINFO_EXTENSION);
|
||||
$thumb_path = $base_path . $this->image_lib->thumb_marker.'.'.$ext;
|
||||
if (sizeof($images) < 2)
|
||||
{
|
||||
$config['image_library'] = 'gd2';
|
||||
$config['source_image'] = $image_path;
|
||||
$config['maintain_ratio'] = TRUE;
|
||||
$config['create_thumb'] = TRUE;
|
||||
$config['width'] = 52;
|
||||
$config['height'] = 32;
|
||||
$this->image_lib->initialize($config);
|
||||
$image = $this->image_lib->resize();
|
||||
$thumb_path = $this->image_lib->full_dst_path;
|
||||
}
|
||||
$this->output->set_content_type(get_mime_by_extension($thumb_path));
|
||||
$this->output->set_output(file_get_contents($thumb_path));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Gives search suggestions based on what is being searched for
|
||||
|
||||
@@ -228,7 +228,7 @@ function get_item_data_row($item,$controller)
|
||||
$images = glob ("uploads/item_pics/" . $item->pic_id . ".*");
|
||||
if (sizeof($images) > 0)
|
||||
{
|
||||
$image.='<a class="rollover" href="'. base_url($images[0]) .'"><img src="'.base_url($images[0]).'"></a>';
|
||||
$image.='<a class="rollover" href="'. base_url($images[0]) .'"><img src="'.site_url('items/pic_thumb/'.$item->pic_id).'"></a>';
|
||||
}
|
||||
}
|
||||
$table_data_row.='<td align="center" width="55px">' . $image . '</td>';
|
||||
|
||||
@@ -33,32 +33,6 @@ $(document).ready(function()
|
||||
function resize_thumbs()
|
||||
{
|
||||
$('a.rollover').imgPreview();
|
||||
$('a.rollover img').each(function()
|
||||
{
|
||||
var maxWidth = 52; // Max width for the image
|
||||
var maxHeight = 32; // Max height for the image
|
||||
var ratio = 0; // Used for aspect ratio
|
||||
var width = $(this).width(); // Current image width
|
||||
var height = $(this).height(); // Current image height
|
||||
|
||||
// Check if the current width is larger than the max
|
||||
if(width > maxWidth){
|
||||
ratio = maxWidth / width; // get ratio for scaling image
|
||||
$(this).css("width", maxWidth); // Set new width
|
||||
$(this).css("height", height * ratio); // Scale height based on ratio
|
||||
height = height * ratio; // Reset height to match scaled image
|
||||
width = width * ratio; // Reset width to match scaled image
|
||||
}
|
||||
|
||||
// Check if current height is larger than max
|
||||
if(height > maxHeight){
|
||||
ratio = maxHeight / height; // get ratio for scaling image
|
||||
$(this).css("height", maxHeight); // Set new height
|
||||
$(this).css("width", width * ratio); // Scale width based on ratio
|
||||
width = width * ratio; // Reset width to match scaled image
|
||||
height = height * ratio; // Reset height to match scaled image
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -55,17 +55,21 @@
|
||||
|
||||
// Re-usable means to add prefix (from setting):
|
||||
function addPrefix(src) {
|
||||
return src.replace(/(\/?)([^\/]+)$/,'$1' + s.thumbPrefix + '$2');
|
||||
return src && src.replace(/(\/?)([^\/]+)$/,'$1' + s.thumbPrefix + '$2');
|
||||
}
|
||||
|
||||
if (s.preloadImages) {
|
||||
(function(i){
|
||||
var tempIMG = new Image(),
|
||||
callee = arguments.callee;
|
||||
tempIMG.src = addPrefix($($collection[i]).attr(s.srcAttr));
|
||||
tempIMG.onload = function(){
|
||||
$collection[i + 1] && callee(i + 1);
|
||||
};
|
||||
var src = $($collection[i]).attr(s.srcAttr)
|
||||
if (src)
|
||||
{
|
||||
tempIMG.src = addPrefix(src);
|
||||
tempIMG.onload = function(){
|
||||
$collection[i + 1] && callee(i + 1);
|
||||
};
|
||||
}
|
||||
})(0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user