- Posts: 18
COMMUNITY FORUM
Image cache questions
- FidoBoy
- Offline
- New Member
Less
More
14 years 3 months ago #72543
by FidoBoy
Replied by FidoBoy on topic Image cache questions
You are right, my mistake, file is item.php not items.php. I'm sorry...
Please Log in or Create an account to join the conversation.
- Abderrahim
- Offline
- New Member
Less
More
- Posts: 7
14 years 3 months ago #72544
by Abderrahim
Replied by Abderrahim on topic Image cache questions
Hi, i have a similar question about images generation!
but, if I want just generate (S and XS) sizes only in cache without (XL,L,M,Generic), and without modifying in source code, where i can found this option in k2 =) ?
[Note:: i have setting "-1" in k2 control panel for (XL,L,...) but images has generated with size = 1x1 = ~1kb ]
thank!
but, if I want just generate (S and XS) sizes only in cache without (XL,L,M,Generic), and without modifying in source code, where i can found this option in k2 =) ?
[Note:: i have setting "-1" in k2 control panel for (XL,L,...) but images has generated with size = 1x1 = ~1kb ]
thank!
Please Log in or Create an account to join the conversation.
- Gerard Croteau
- Offline
- New Member
Less
More
- Posts: 7
14 years 1 month ago #72545
by Gerard Croteau
Replied by Gerard Croteau on topic Image cache questions
thank you
I add that peices of code
but I still have the same problem
the thumbnails in the blog author are all resized extra small ( ie. from original file of 100 X 100, they are all resized to 14 X 14)
I flushed the cache, I refreshed the menus, always the same problem
thumbnails are not of the size entered in the set up
any suggestions ?
thanks
Kristiyan Ivanchevski said:Thanks. Will try ASAP.
fidoboy said:Well, finally i've created a patch to allow image cache reconstruction from sources using current image size parameters. You must open the file items.php (into the models folder of frontpage component). Locate the function prepareItem and then into this function, locate the following lines:
replace those lines with this code:
and finally at the end of class K2ModelItem (just before the last } ) add this new function:
That's all, i hope that you enjoy the new function!! Now if you delete some or all images from the cache folder, they are rebuilded from their sources (using the new size if it has changed). It works fine for me...
kind regards,
I add that peices of code
but I still have the same problem
the thumbnails in the blog author are all resized extra small ( ie. from original file of 100 X 100, they are all resized to 14 X 14)
I flushed the cache, I refreshed the menus, always the same problem
thumbnails are not of the size entered in the set up
any suggestions ?
thanks
Kristiyan Ivanchevski said:Thanks. Will try ASAP.
fidoboy said:Well, finally i've created a patch to allow image cache reconstruction from sources using current image size parameters. You must open the file items.php (into the models folder of frontpage component). Locate the function prepareItem and then into this function, locate the following lines:
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.jpg'))<br/>
$item->imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.jpg'))<br/>
$item->imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.jpg'))<br/>
$item->imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.jpg'))<br/>
$item->imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.jpg'))<br/>
$item->imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.jpg'))<br/>
$item->imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg';<br/>
replace those lines with this code:
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.jpg'))
$item->imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg';
else
$item->imageXSmall = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'xsmall');
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.jpg'))
$item->imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg';
else
$item->imageSmall = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'small');
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.jpg'))
$item->imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg';
else
$item->imageMedium = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'medium');
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.jpg'))
$item->imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg';
else
$item->imageLarge = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'large');
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.jpg'))
$item->imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg';
else
$item->imageXLarge = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'xlarge');
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.jpg'))
$item->imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg';
else
$item->imageGeneric = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'generic');
and finally at the end of class K2ModelItem (just before the last } ) add this new function:
function rebuildImageFromSrc ($srcImage, $params, $newImgSize) {
if (!JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'src'.DS.$srcImage.'.jpg')) return "";
require_once (JPATH_COMPONENT_ADMINISTRATOR.DS.'lib'.DS.'class.upload.php');
$handle = new Upload(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'src'.DS.$srcImage.'.jpg');
$handle->allowed = array('image/*');
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'jpg';
$handle->jpeg_quality = $params->get('imagesQuality');
$handle->file_auto_rename = false;
$handle->file_overwrite = false;
switch($newImgSize) {
case 'xlarge':
$handle->file_new_name_body = $srcImage.'_XL';
$imageWidth = $params->get('itemImageXL', '800');
$handle->image_x = $imageWidth;
break;
case 'large':
$handle->file_new_name_body = $srcImage.'_L';
$imageWidth = $params->get('itemImageL', '600');
$handle->image_x = $imageWidth;
break;
case 'medium':
$handle->file_new_name_body = $srcImage.'_M';
$imageWidth = $params->get('itemImageM', '400');
$handle->image_x = $imageWidth;
break;
case 'small':
$handle->file_new_name_body = $srcImage.'_S';
$imageWidth = $params->get('itemImageS', '200');
$handle->image_x = $imageWidth;
break;
case 'xsmall':
$handle->file_new_name_body = $srcImage.'_XS';
$imageWidth = $params->get('itemImageXS', '100');
$handle->image_x = $imageWidth;
break;
case 'generic':
$handle->file_new_name_body = $srcImage.'_Generic';
$imageWidth = $params->get('itemImageGeneric', '300');
$handle->image_x = $imageWidth;
break;
}
$handle->Process(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache');
return JURI::root().'media/k2/items/cache/'.$handle->file_dst_name_body.'.jpg';
}
That's all, i hope that you enjoy the new function!! Now if you delete some or all images from the cache folder, they are rebuilded from their sources (using the new size if it has changed). It works fine for me...
kind regards,
Please Log in or Create an account to join the conversation.
- Gerard Croteau
- Offline
- New Member
Less
More
- Posts: 7
14 years 1 month ago #72546
by Gerard Croteau
Replied by Gerard Croteau on topic Image cache questions
something more :
I use CB as I doing a migration to J15 from J1015. CB was installed to the former site and I saw that K2 login can't manage the database of CB
do CB setup for avatar sizes bug K2 avatar sizes, even they are set up to be the same ?
thanks
Gerard Croteau said:thank you
I add that peices of code
but I still have the same problem
the thumbnails in the blog author are all resized extra small ( ie. from original file of 100 X 100, they are all resized to 14 X 14)
I flushed the cache, I refreshed the menus, always the same problem
thumbnails are not of the size entered in the set up
any suggestions ?
thanks
Kristiyan Ivanchevski said:Thanks. Will try ASAP. fidoboy said:Well, finally i've created a patch to allow image cache reconstruction from sources using current image size parameters. You must open the file items.php (into the models folder of frontpage component). Locate the function prepareItem and then into this function, locate the following lines:
replace those lines with this code:
and finally at the end of class K2ModelItem (just before the last } ) add this new function:
That's all, i hope that you enjoy the new function!! Now if you delete some or all images from the cache folder, they are rebuilded from their sources (using the new size if it has changed). It works fine for me...
kind regards,
I use CB as I doing a migration to J15 from J1015. CB was installed to the former site and I saw that K2 login can't manage the database of CB
do CB setup for avatar sizes bug K2 avatar sizes, even they are set up to be the same ?
thanks
Gerard Croteau said:thank you
I add that peices of code
but I still have the same problem
the thumbnails in the blog author are all resized extra small ( ie. from original file of 100 X 100, they are all resized to 14 X 14)
I flushed the cache, I refreshed the menus, always the same problem
thumbnails are not of the size entered in the set up
any suggestions ?
thanks
Kristiyan Ivanchevski said:Thanks. Will try ASAP. fidoboy said:Well, finally i've created a patch to allow image cache reconstruction from sources using current image size parameters. You must open the file items.php (into the models folder of frontpage component). Locate the function prepareItem and then into this function, locate the following lines:
<br/> if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.jpg'))<br/>
$item->imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.jpg'))<br/>
$item->imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.jpg'))<br/>
$item->imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.jpg'))<br/>
$item->imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.jpg'))<br/>
$item->imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.jpg'))<br/>
$item->imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg';<br/>
replace those lines with this code:
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.jpg'))
$item->imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg';
else
$item->imageXSmall = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'xsmall');
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.jpg'))
$item->imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg';
else
$item->imageSmall = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'small');
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.jpg'))
$item->imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg';
else
$item->imageMedium = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'medium');
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.jpg'))
$item->imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg';
else
$item->imageLarge = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'large');
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.jpg'))
$item->imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg';
else
$item->imageXLarge = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'xlarge');
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.jpg'))
$item->imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg';
else
$item->imageGeneric = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'generic');
and finally at the end of class K2ModelItem (just before the last } ) add this new function:
function rebuildImageFromSrc ($srcImage, $params, $newImgSize) {
if (!JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'src'.DS.$srcImage.'.jpg')) return "";
require_once (JPATH_COMPONENT_ADMINISTRATOR.DS.'lib'.DS.'class.upload.php');
$handle = new Upload(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'src'.DS.$srcImage.'.jpg');
$handle->allowed = array('image/*');
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'jpg';
$handle->jpeg_quality = $params->get('imagesQuality');
$handle->file_auto_rename = false;
$handle->file_overwrite = false;
switch($newImgSize) {
case 'xlarge':
$handle->file_new_name_body = $srcImage.'_XL';
$imageWidth = $params->get('itemImageXL', '800');
$handle->image_x = $imageWidth;
break;
case 'large':
$handle->file_new_name_body = $srcImage.'_L';
$imageWidth = $params->get('itemImageL', '600');
$handle->image_x = $imageWidth;
break;
case 'medium':
$handle->file_new_name_body = $srcImage.'_M';
$imageWidth = $params->get('itemImageM', '400');
$handle->image_x = $imageWidth;
break;
case 'small':
$handle->file_new_name_body = $srcImage.'_S';
$imageWidth = $params->get('itemImageS', '200');
$handle->image_x = $imageWidth;
break;
case 'xsmall':
$handle->file_new_name_body = $srcImage.'_XS';
$imageWidth = $params->get('itemImageXS', '100');
$handle->image_x = $imageWidth;
break;
case 'generic':
$handle->file_new_name_body = $srcImage.'_Generic';
$imageWidth = $params->get('itemImageGeneric', '300');
$handle->image_x = $imageWidth;
break;
}
$handle->Process(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache');
return JURI::root().'media/k2/items/cache/'.$handle->file_dst_name_body.'.jpg';
}
That's all, i hope that you enjoy the new function!! Now if you delete some or all images from the cache folder, they are rebuilded from their sources (using the new size if it has changed). It works fine for me...
kind regards,
Please Log in or Create an account to join the conversation.
- BBC
- Offline
- Platinum Member
Less
More
- Posts: 663
13 years 9 months ago #72547
by BBC
Replied by BBC on topic Image cache questions
Did you change item.php in administrator/components? Or just /components/com_k2.
Because I don´t get it to work. How is cache rebuild? By frontpage refresh? Or save in K2 admin panel`?
Because I don´t get it to work. How is cache rebuild? By frontpage refresh? Or save in K2 admin panel`?
Please Log in or Create an account to join the conversation.
- BBC
- Offline
- Platinum Member
Less
More
- Posts: 663
13 years 9 months ago #72548
by BBC
Replied by BBC on topic Image cache questions
OK, it works. Browser cache delay. But can´t get it to work with new dimensions (height hack).
href="community.getk2.org/forum/topics/creat-thumbnail-by-width-and?id=3536014%3ATopic%3A20874&page=4#comments
They are restored with old width settings, height hack is ignored. If i make new item hack is respected.
Thanks for solution.
href="community.getk2.org/forum/topics/creat-thumbnail-by-width-and?id=3536014%3ATopic%3A20874&page=4#comments
They are restored with old width settings, height hack is ignored. If i make new item hack is respected.
Thanks for solution.
Please Log in or Create an account to join the conversation.
- dvlancer
- Offline
- New Member
13 years 8 months ago #72549
by dvlancer
Replied by dvlancer on topic Image cache questions
Just what I was looking for!
fidoboy said:Well, finally i've created a patch to allow image cache reconstruction from sources using current image size parameters. You must open the file items.php (into the models folder of frontpage component). Locate the function prepareItem and then into this function, locate the following lines:
replace those lines with this code:
and finally at the end of class K2ModelItem (just before the last } ) add this new function:
That's all, i hope that you enjoy the new function!! Now if you delete some or all images from the cache folder, they are rebuilded from their sources (using the new size if it has changed). It works fine for me...
kind regards,
fidoboy said:Well, finally i've created a patch to allow image cache reconstruction from sources using current image size parameters. You must open the file items.php (into the models folder of frontpage component). Locate the function prepareItem and then into this function, locate the following lines:
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.jpg'))<br/>
$item->imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.jpg'))<br/>
$item->imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.jpg'))<br/>
$item->imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.jpg'))<br/>
$item->imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.jpg'))<br/>
$item->imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.jpg'))<br/>
$item->imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg';<br/>
replace those lines with this code:
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.jpg'))
$item->imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg';
else
$item->imageXSmall = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'xsmall');
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.jpg'))
$item->imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg';
else
$item->imageSmall = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'small');
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.jpg'))
$item->imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg';
else
$item->imageMedium = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'medium');
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.jpg'))
$item->imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg';
else
$item->imageLarge = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'large');
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.jpg'))
$item->imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg';
else
$item->imageXLarge = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'xlarge');
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.jpg'))
$item->imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg';
else
$item->imageGeneric = K2ModelItem::rebuildImageFromSrc(md5("Image".$item->id), $item->params, 'generic');
and finally at the end of class K2ModelItem (just before the last } ) add this new function:
function rebuildImageFromSrc ($srcImage, $params, $newImgSize) {
if (!JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'src'.DS.$srcImage.'.jpg')) return "";
require_once (JPATH_COMPONENT_ADMINISTRATOR.DS.'lib'.DS.'class.upload.php');
$handle = new Upload(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'src'.DS.$srcImage.'.jpg');
$handle->allowed = array('image/*');
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'jpg';
$handle->jpeg_quality = $params->get('imagesQuality');
$handle->file_auto_rename = false;
$handle->file_overwrite = false;
switch($newImgSize) {
case 'xlarge':
$handle->file_new_name_body = $srcImage.'_XL';
$imageWidth = $params->get('itemImageXL', '800');
$handle->image_x = $imageWidth;
break;
case 'large':
$handle->file_new_name_body = $srcImage.'_L';
$imageWidth = $params->get('itemImageL', '600');
$handle->image_x = $imageWidth;
break;
case 'medium':
$handle->file_new_name_body = $srcImage.'_M';
$imageWidth = $params->get('itemImageM', '400');
$handle->image_x = $imageWidth;
break;
case 'small':
$handle->file_new_name_body = $srcImage.'_S';
$imageWidth = $params->get('itemImageS', '200');
$handle->image_x = $imageWidth;
break;
case 'xsmall':
$handle->file_new_name_body = $srcImage.'_XS';
$imageWidth = $params->get('itemImageXS', '100');
$handle->image_x = $imageWidth;
break;
case 'generic':
$handle->file_new_name_body = $srcImage.'_Generic';
$imageWidth = $params->get('itemImageGeneric', '300');
$handle->image_x = $imageWidth;
break;
}
$handle->Process(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache');
return JURI::root().'media/k2/items/cache/'.$handle->file_dst_name_body.'.jpg';
}
That's all, i hope that you enjoy the new function!! Now if you delete some or all images from the cache folder, they are rebuilded from their sources (using the new size if it has changed). It works fine for me...
kind regards,
Please Log in or Create an account to join the conversation.
- Adamo
- Offline
- Junior Member
Less
More
- Posts: 29
13 years 6 months ago #72550
by Adamo
Replied by Adamo on topic Image cache questions
Excuse me for the trivial question but, if there is a necessity and if there is also a solution why this solution is not implemented in the main project?
I ask this because i have the same problem and i also know how to use the hack here proposed but i don't like hack the core because at avery update i have to check if i have to re-hack the code.
Would not it be easier if the improvement is implemented in the K2 component? How can we propose improvements?
I ask this because i have the same problem and i also know how to use the hack here proposed but i don't like hack the core because at avery update i have to check if i have to re-hack the code.
Would not it be easier if the improvement is implemented in the K2 component? How can we propose improvements?
Please Log in or Create an account to join the conversation.
- Alfonso F. Moreno
- Offline
- Elite Member
Less
More
- Posts: 169
13 years 6 months ago #72551
by Alfonso F. Moreno
Replied by Alfonso F. Moreno on topic Image cache questions
I'm with youAdrabi its very exensive in space to resize all the images in 6 different sizes what means six images per article. I think there is no option to avoid rezizing from all sizes. Maybe the only way its to delete from cache if you are not going to use it once made the resizing or, as you say, let the other sizes 1x1pixels.
Adrabi Abderrahim said:Hi, i have a similar question about images generation! but, if I want just generate (S and XS) sizes only in cache without (XL,L,M,Generic), and without modifying in source code, where i can found this option in k2 =) ?
[Note:: i have setting "-1" in k2 control panel for (XL,L,...) but images has generated with size = 1x1 = ~1kb ]
thank!
Adrabi Abderrahim said:Hi, i have a similar question about images generation! but, if I want just generate (S and XS) sizes only in cache without (XL,L,M,Generic), and without modifying in source code, where i can found this option in k2 =) ?
[Note:: i have setting "-1" in k2 control panel for (XL,L,...) but images has generated with size = 1x1 = ~1kb ]
thank!
Please Log in or Create an account to join the conversation.
- HJM Cortooms
- Offline
- Junior Member
Less
More
- Posts: 22
13 years 5 months ago #72552
by HJM Cortooms
Replied by HJM Cortooms on topic Image cache questions
Wouldn't it be nice if someone uploaded the hacked item.php file for version 2.4.1?
Please Log in or Create an account to join the conversation.