Keyword

Image cache questions

More
15 years 4 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.

More
15 years 4 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!

Please Log in or Create an account to join the conversation.

More
15 years 3 months 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:
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_XS.jpg'))<br/>
$item-&gt;imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_XS.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_S.jpg'))<br/>
$item-&gt;imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_S.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_M.jpg'))<br/>
$item-&gt;imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_M.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_L.jpg'))<br/>
$item-&gt;imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_L.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_XL.jpg'))<br/>
$item-&gt;imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_XL.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_Generic.jpg'))<br/>
$item-&gt;imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;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-&gt;id).'_XS.jpg'))
$item-&gt;imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_XS.jpg';
else
$item-&gt;imageXSmall = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;params, 'xsmall');

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_S.jpg'))
$item-&gt;imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_S.jpg';
else
$item-&gt;imageSmall = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;params, 'small');

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_M.jpg'))
$item-&gt;imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_M.jpg';
else
$item-&gt;imageMedium = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;params, 'medium');

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_L.jpg'))
$item-&gt;imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_L.jpg';
else
$item-&gt;imageLarge = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;params, 'large');

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_XL.jpg'))
$item-&gt;imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_XL.jpg';
else
$item-&gt;imageXLarge = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;params, 'xlarge');

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_Generic.jpg'))
$item-&gt;imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_Generic.jpg';
else
$item-&gt;imageGeneric = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;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-&gt;allowed = array('image/*');

$handle-&gt;image_resize = true;
$handle-&gt;image_ratio_y = true;
$handle-&gt;image_convert = 'jpg';
$handle-&gt;jpeg_quality = $params-&gt;get('imagesQuality');
$handle-&gt;file_auto_rename = false;
$handle-&gt;file_overwrite = false;

switch($newImgSize) {
case 'xlarge':
$handle-&gt;file_new_name_body = $srcImage.'_XL';
$imageWidth = $params-&gt;get('itemImageXL', '800');
$handle-&gt;image_x = $imageWidth;
break;
case 'large':
$handle-&gt;file_new_name_body = $srcImage.'_L';
$imageWidth = $params-&gt;get('itemImageL', '600');
$handle-&gt;image_x = $imageWidth;
break;
case 'medium':
$handle-&gt;file_new_name_body = $srcImage.'_M';
$imageWidth = $params-&gt;get('itemImageM', '400');
$handle-&gt;image_x = $imageWidth;
break;
case 'small':
$handle-&gt;file_new_name_body = $srcImage.'_S';
$imageWidth = $params-&gt;get('itemImageS', '200');
$handle-&gt;image_x = $imageWidth;
break;
case 'xsmall':
$handle-&gt;file_new_name_body = $srcImage.'_XS';
$imageWidth = $params-&gt;get('itemImageXS', '100');
$handle-&gt;image_x = $imageWidth;
break;
case 'generic':
$handle-&gt;file_new_name_body = $srcImage.'_Generic';
$imageWidth = $params-&gt;get('itemImageGeneric', '300');
$handle-&gt;image_x = $imageWidth;
break;
}
$handle-&gt;Process(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache');

return JURI::root().'media/k2/items/cache/'.$handle-&gt;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.

More
15 years 3 months 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:
<br/> if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_XS.jpg'))<br/>
$item-&gt;imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_XS.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_S.jpg'))<br/>
$item-&gt;imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_S.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_M.jpg'))<br/>
$item-&gt;imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_M.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_L.jpg'))<br/>
$item-&gt;imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_L.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_XL.jpg'))<br/>
$item-&gt;imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_XL.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_Generic.jpg'))<br/>
$item-&gt;imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;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-&gt;id).'_XS.jpg'))
$item-&gt;imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_XS.jpg';
else
$item-&gt;imageXSmall = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;params, 'xsmall');

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_S.jpg'))
$item-&gt;imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_S.jpg';
else
$item-&gt;imageSmall = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;params, 'small');

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_M.jpg'))
$item-&gt;imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_M.jpg';
else
$item-&gt;imageMedium = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;params, 'medium');

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_L.jpg'))
$item-&gt;imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_L.jpg';
else
$item-&gt;imageLarge = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;params, 'large');

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_XL.jpg'))
$item-&gt;imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_XL.jpg';
else
$item-&gt;imageXLarge = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;params, 'xlarge');

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_Generic.jpg'))
$item-&gt;imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_Generic.jpg';
else
$item-&gt;imageGeneric = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;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-&gt;allowed = array('image/*');

$handle-&gt;image_resize = true;
$handle-&gt;image_ratio_y = true;
$handle-&gt;image_convert = 'jpg';
$handle-&gt;jpeg_quality = $params-&gt;get('imagesQuality');
$handle-&gt;file_auto_rename = false;
$handle-&gt;file_overwrite = false;

switch($newImgSize) {
case 'xlarge':
$handle-&gt;file_new_name_body = $srcImage.'_XL';
$imageWidth = $params-&gt;get('itemImageXL', '800');
$handle-&gt;image_x = $imageWidth;
break;
case 'large':
$handle-&gt;file_new_name_body = $srcImage.'_L';
$imageWidth = $params-&gt;get('itemImageL', '600');
$handle-&gt;image_x = $imageWidth;
break;
case 'medium':
$handle-&gt;file_new_name_body = $srcImage.'_M';
$imageWidth = $params-&gt;get('itemImageM', '400');
$handle-&gt;image_x = $imageWidth;
break;
case 'small':
$handle-&gt;file_new_name_body = $srcImage.'_S';
$imageWidth = $params-&gt;get('itemImageS', '200');
$handle-&gt;image_x = $imageWidth;
break;
case 'xsmall':
$handle-&gt;file_new_name_body = $srcImage.'_XS';
$imageWidth = $params-&gt;get('itemImageXS', '100');
$handle-&gt;image_x = $imageWidth;
break;
case 'generic':
$handle-&gt;file_new_name_body = $srcImage.'_Generic';
$imageWidth = $params-&gt;get('itemImageGeneric', '300');
$handle-&gt;image_x = $imageWidth;
break;
}
$handle-&gt;Process(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache');

return JURI::root().'media/k2/items/cache/'.$handle-&gt;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.

More
14 years 10 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`?

Please Log in or Create an account to join the conversation.

More
14 years 10 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.

Please Log in or Create an account to join the conversation.

More
14 years 9 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:
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_XS.jpg'))<br/>
$item-&gt;imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_XS.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_S.jpg'))<br/>
$item-&gt;imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_S.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_M.jpg'))<br/>
$item-&gt;imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_M.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_L.jpg'))<br/>
$item-&gt;imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_L.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_XL.jpg'))<br/>
$item-&gt;imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_XL.jpg';<br/>
<br/>
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_Generic.jpg'))<br/>
$item-&gt;imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;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-&gt;id).'_XS.jpg'))
$item-&gt;imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_XS.jpg';
else
$item-&gt;imageXSmall = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;params, 'xsmall');

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_S.jpg'))
$item-&gt;imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_S.jpg';
else
$item-&gt;imageSmall = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;params, 'small');

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_M.jpg'))
$item-&gt;imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_M.jpg';
else
$item-&gt;imageMedium = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;params, 'medium');

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_L.jpg'))
$item-&gt;imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_L.jpg';
else
$item-&gt;imageLarge = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;params, 'large');

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_XL.jpg'))
$item-&gt;imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_XL.jpg';
else
$item-&gt;imageXLarge = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;params, 'xlarge');

if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item-&gt;id).'_Generic.jpg'))
$item-&gt;imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item-&gt;id).'_Generic.jpg';
else
$item-&gt;imageGeneric = K2ModelItem::rebuildImageFromSrc(md5("Image".$item-&gt;id), $item-&gt;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-&gt;allowed = array('image/*');

$handle-&gt;image_resize = true;
$handle-&gt;image_ratio_y = true;
$handle-&gt;image_convert = 'jpg';
$handle-&gt;jpeg_quality = $params-&gt;get('imagesQuality');
$handle-&gt;file_auto_rename = false;
$handle-&gt;file_overwrite = false;

switch($newImgSize) {
case 'xlarge':
$handle-&gt;file_new_name_body = $srcImage.'_XL';
$imageWidth = $params-&gt;get('itemImageXL', '800');
$handle-&gt;image_x = $imageWidth;
break;
case 'large':
$handle-&gt;file_new_name_body = $srcImage.'_L';
$imageWidth = $params-&gt;get('itemImageL', '600');
$handle-&gt;image_x = $imageWidth;
break;
case 'medium':
$handle-&gt;file_new_name_body = $srcImage.'_M';
$imageWidth = $params-&gt;get('itemImageM', '400');
$handle-&gt;image_x = $imageWidth;
break;
case 'small':
$handle-&gt;file_new_name_body = $srcImage.'_S';
$imageWidth = $params-&gt;get('itemImageS', '200');
$handle-&gt;image_x = $imageWidth;
break;
case 'xsmall':
$handle-&gt;file_new_name_body = $srcImage.'_XS';
$imageWidth = $params-&gt;get('itemImageXS', '100');
$handle-&gt;image_x = $imageWidth;
break;
case 'generic':
$handle-&gt;file_new_name_body = $srcImage.'_Generic';
$imageWidth = $params-&gt;get('itemImageGeneric', '300');
$handle-&gt;image_x = $imageWidth;
break;
}
$handle-&gt;Process(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache');

return JURI::root().'media/k2/items/cache/'.$handle-&gt;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.

More
14 years 7 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?

Please Log in or Create an account to join the conversation.

  • Alfonso F. Moreno
  • Alfonso F. Moreno's Avatar
  • Offline
  • Elite Member
More
14 years 7 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!

Please Log in or Create an account to join the conversation.

More
14 years 6 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.

More
14 years 4 months ago #72553 by BBC
Replied by BBC on topic Image cache questions
Exactly before last } in item.php.
Before last line in that file.

But, this hack brings another problem. If you use crop hack (custom width and height of images), there is no way cache will be rebuilded with respect for that.

Please Log in or Create an account to join the conversation.

More
14 years 4 months ago #72554 by BBC
Replied by BBC on topic Image cache questions
Finally it is working as i want.

I edited a little bit second part to suit my needs.
Small and Xsmall cropped for categories thumbs (different width and height, not square)
And have $handle-&gt;image_ratio_y = true; for large images. (those that go in detailed item view)

Just to figure out how to put attachment in this stupid forum.


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-&gt;allowed = array('image/*');

$handle-&gt;image_resize = true;
//$handle-&gt;image_ratio_y = true;
$handle-&gt;image_convert = 'jpg';
$handle-&gt;jpeg_quality = $params-&gt;get('imagesQuality');
$handle-&gt;file_auto_rename = false;
$handle-&gt;file_overwrite = false;

switch($newImgSize) {
case 'xlarge':
$handle-&gt;file_new_name_body = $srcImage.'_XL';
if (JRequest::getInt('itemImageXL')) {
$imageWidth = JRequest::getInt('itemImageXL');
} else {
$imageWidth = $params-&gt;get('itemImageXL', '800');
}
if (JRequest::getInt('itemImageXL_Height')) {
$imageHeight = JRequest::getInt('itemImageXL_Height');
} else {
$imageHeight = $params-&gt;get('itemImageXL_Height', '800');
}
$handle-&gt;image_x = $imageWidth;
$handle-&gt;image_y = $imageHeight;
$handle-&gt;image_ratio_y = true;
$handle-&gt;image_ratio_crop = true;break;
case 'large':
$handle-&gt;file_new_name_body = $srcImage.'_L';
if (JRequest::getInt('itemImageL')) {
$imageWidth = JRequest::getInt('itemImageL');
} else {
$imageWidth = $params-&gt;get('itemImageL', '600');
}
if (JRequest::getInt('itemImageL_Height')) {
$imageHeight = JRequest::getInt('itemImageL_Height');
} else {
$imageHeight = $params-&gt;get('itemImageL_Height', '600');
}
$handle-&gt;image_x = $imageWidth;
$handle-&gt;image_y = $imageHeight;
$handle-&gt;image_ratio_y = true;
$handle-&gt;image_ratio_crop = true;break;
case 'medium':
$handle-&gt;file_new_name_body = $srcImage.'_M';
if (JRequest::getInt('itemImageM')) {
$imageWidth = JRequest::getInt('itemImageM');
} else {
$imageWidth = $params-&gt;get('itemImageM', '400');
}
if (JRequest::getInt('itemImageM_Height')) {
$imageHeight = JRequest::getInt('itemImageM_Height');
} else {
$imageHeight = $params-&gt;get('itemImageM_Height', '400');
}
$handle-&gt;image_x = $imageWidth;
$handle-&gt;image_y = $imageHeight;
$handle-&gt;image_ratio_y = true;
$handle-&gt;image_ratio_crop = true;
break;
case 'small':
$handle-&gt;file_new_name_body = $srcImage.'_S';
if (JRequest::getInt('itemImageS')) {
$imageWidth = JRequest::getInt('itemImageS');
} else {
$imageWidth = $params-&gt;get('itemImageS', '200');
}
if (JRequest::getInt('itemImageS_Height')) {
$imageHeight = JRequest::getInt('itemImageS_Height');
} else {
$imageHeight = $params-&gt;get('itemImageS_Height', '200');
}
$handle-&gt;image_x = $imageWidth;
$handle-&gt;image_y = $imageHeight;
$handle-&gt;image_ratio_crop = true;
break;
case 'xsmall':
$handle-&gt;file_new_name_body = $srcImage.'_XS';
if (JRequest::getInt('itemImageXS')) {
$imageWidth = JRequest::getInt('itemImageXS');
} else {
$imageWidth = $params-&gt;get('itemImageXS', '100');
}
if (JRequest::getInt('itemImageXS_Height')) {
$imageHeight = JRequest::getInt('itemImageXS_Height');
} else {
$imageHeight = $params-&gt;get('itemImageXS_Height', '100');
}
$handle-&gt;image_x = $imageWidth;
$handle-&gt;image_y = $imageHeight;
$handle-&gt;image_ratio_crop = true;
break;
case 'generic':
$handle-&gt;file_new_name_body = $srcImage.'_Generic';
$imageWidth = $params-&gt;get('itemImageGeneric', '300');
$imageHeight = $params-&gt;get('itemImageGeneric_Height', '300');
$handle-&gt;image_x = $imageWidth;
$handle-&gt;image_y = $imageHeight;
$handle-&gt;image_ratio_crop = true;
break;
}
$handle-&gt;Process(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache');

return JURI::root().'media/k2/items/cache/'.$handle-&gt;file_dst_name_body.'.jpg';
}

Please Log in or Create an account to join the conversation.

More
14 years 4 months ago #72555 by BBC
Replied by BBC on topic Image cache questions
My solution is in conjuction with this hack:

community.getk2.org/forum/topics/creat-thumbnail-by-width-and?commentId=3536014%3AComment%3A21223

 

If you don´t crop or don´t have custom width and height then you don´t need this.

Please Log in or Create an account to join the conversation.

More
14 years 4 months ago #72556 by BBC
Replied by BBC on topic Image cache questions
But use deleting cache from items/cache only in emergency. If you run out of disk space at hosting.
It is so resource demanding.

And be careful not to delete from items/src. It coud be plenty of time working with every item and upload all images again.

Please Log in or Create an account to join the conversation.

More
14 years 4 months ago #72557 by JoomlaWorks
Replied by JoomlaWorks on topic Image cache questions
Thanks for this folks.

 

We knew there would come a time when people would face this issue... This is the time when someone has used K2 for a long time and now is redesigning their site and wants to make use of different image sizes, from the images already inside K2.

 

While we addressed this (somehow) in K2 v2.3 (if I recall properly), by setting the item image width values on the &lt;img&gt; elements themselves, it's really not the best approach...

 

It's on our plans (even for 2.5) to address this issue better. One solution is the one mentioned in this forum. But we need to examine this more carefully, so people's sites don't break if the change a width value somewhere and K2 tries to regenerate a few hundred pics on the frontpage of the site or some long category list ;)

 

More soon via a blog post.

Please Log in or Create an account to join the conversation.

More
14 years 4 months ago #72558 by BBC
Replied by BBC on topic Image cache questions
Thanks for that. It was really needed. Mostly because it is not cover by templates override, and you have to tweak code every time. And every time different, different wishes at different sites.

 

If you can add just one simple extra field for video streaming it would be near perfect extension. And it opens more posibility for this extension.

 

One extra field where you just put direct link of video stream. (all with .svf, .avi, .flv....ec, at the end)

As Insert media plugin for JCE does. It never failed to show some streamed video, doesn´t matter what website it was.

As long as i found direct vieo link with Firefox add-on. (for instance, community.getk2.org/video-333.flv)

 

So it is simple solution. It goes well to put code with JCE, or some custom extra field.

 

But, if you could make such extra field, you are years ahead of other CCK extensions.

 

 

Please Log in or Create an account to join the conversation.

More
14 years 3 months ago #72559 by Ivaylo Cherkezov
Replied by Ivaylo Cherkezov on topic Image cache questions
Your solution is great for recreating the pictures. After deleting the cache all my pictures was recreated with the same size which is great. Now when I upload a new picture the width is the same as the others but the height is different. I need to delete the image from the cache and when it's recreated it's the same size as the others. All these works fine on my localhost server with PHP 5.3.1 but on my hosting with PHP 5.2.6  when I open a category to recreate the pictures it gives me a white page. My questions are:


Is it possible on upload the picture's size to be the same as the others and in this way to avoid deleting the picture and recreating it?
Why I get this white page?

Thanks in advance!

Please Log in or Create an account to join the conversation.

More
14 years 3 months ago #72560 by BBC
Replied by BBC on topic Image cache questions
2. If you can see your server error logs, you would see errors about your script is trying to use more resources then it is allowed.

 

Be careful with this posibillity to recreate all images at once. You could get kicked out from hosting.

 

This codes of lines need seriously add by K2 developers. To make some delay functions, so that server accept it.

As other gallery extensions have.

Please Log in or Create an account to join the conversation.

More
14 years 3 months ago #72561 by Ivaylo Cherkezov
Replied by Ivaylo Cherkezov on topic Image cache questions
About 2. the error was in my template, sorry for bothering you and thanks for the advise. I am more interested in the first question, why I need to upload the image and deleted so it can be resized as the other images?

Please Log in or Create an account to join the conversation.

More
14 years 3 months ago #72562 by ansi.alpha
Replied by ansi.alpha on topic Image cache questions
if anyone still need another solution , you might try this.i made it to when i transferred my wordpress to joomla k2 "troublesome".1. make php file at the top of your joomla directory. "anything.php"2.copy and paste the code in it then check it in your browser and wait until it finish loading.3. when it finish loading, change the 2nd parameter of recreateImg function in the while loop with the k2 Width you variable you want.4.if you get error memory limit reach just refresh and it will continue from where it stop."it happens if your image has really high size"5.delete this php file when you are done creating all images you want.

NOTE: this doesn't create md5 names of images but it could with abit coding. and if your imagesdosn't have md5 names,your images wont work in your k2.&lt;?php/** * $XS,$S,$M,$L,$XL,$Generic are k2 widths of new recreateImgd images in px . "you can find them in k2 panel" * you will need them change 2nd parameter of recreateImg function in the while loop after it finish generating files successfully. * probably not the default size setting. * if you change it ,change switch statment numbers to match them. */$XS = 133;$S = 409;$M = 745;$L = 766;$XL = 1066;$Generic = 300;//path to src folder of your images$srcPath = "./media/k2/items/src/";function recreateImg($file, $k2Width){    global $srcPath;    $imgPath = $srcPath . $file;    $imgname = $file;    // if you change k2 widths variables ,    // you will need to change numbers of each case to match them.    switch ($k2Width) {        case 133:            $size = 'XS';            break;        case 409:            $size = 'S';            break;        case 745:            $size = 'M';            break;        case 766:            $size = 'L';            break;        case 1066:            $size = 'XL';            break;        case 300:            $size = 'Generic';            break;    }    // the new image name and path to save it    $save = "./media/k2/items/cache/" . $imgname . '_' . $size . '.jpg';    if (file_exists($save)) {        echo $imgname . '_' . $size . '.jpg' . ' :Image exisit! &lt;br/&gt;';    } else {        $pic = imagecreatefromjpeg($imgPath);        $width = imagesx($pic);        $height = imagesy($pic);        $ratio = $k2Width / $width;        $newHeight = $height * $ratio;        $new_image = imagecreatetruecolor($k2Width, $newHeight);        imagecopyresampled($new_image, $pic, 0, 0, 0, 0, $k2Width, $newHeight, $width, $height);        imagedestroy($pic);        imagejpeg($new_image, $save);        imagedestroy($new_image);    }} // end of function//calling the function while looping each file if its jpg image$folder = opendir($srcPath);while ($file = readdir($folder)) {    if (substr($file, -4) == ".jpg") { //you can do images generations 1 size at one time by changing 2nd parameter .        recreateImg($file, $XS);    }}closedir($folder);?&gt;

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum