COMMUNITY FORUM
Image cache questions
- Kelsey Brookes
-
Topic Author
- Offline
- Elite Member
I've been working on a fairly large site that makes extensive use of the various image sizes available in K2. Different areas have different presentations of the various images.
It's been working very well, but in the last day or so seems to have developed a problem - new images are showing up in the wrong size in item lists derived from tags. I haven't changed the size in the settings, but the new images are showing up wrongly.
This is also happening with mod_k2_content.
I've tried re-uploading images with no success.
Is there a way to clear the image cache and get it to rebuild the images properly?
Has anyone had any other issues like this?
Please Log in or Create an account to join the conversation.
- olsen
-
- Offline
- Elite Member
- Joomla and K2 Freelancer
rgds
Didn't solve your issues?? Why dont you consider hire me? Email me or contact me www.xevedigital.com for details
Please Log in or Create an account to join the conversation.
- Kelsey Brookes
-
Topic Author
- Offline
- Elite Member
Sure there should be a way to do this within K2 itself?
Please Log in or Create an account to join the conversation.
- olsen
-
- Offline
- Elite Member
- Joomla and K2 Freelancer
rgds
Kelsey Brookes said:Thanks for that - will it totally stuff up if I delete the cached images or will they be rebuilt?
Sure there should be a way to do this within K2 itself?
Didn't solve your issues?? Why dont you consider hire me? Email me or contact me www.xevedigital.com for details
Please Log in or Create an account to join the conversation.
- Kristiyan Ivanchevski
-
- Offline
- Junior Member
- Posts: 23
K2 v2.1
Please Log in or Create an account to join the conversation.
- anthony menzies
-
- Offline
- New Member
- Posts: 2
Please Log in or Create an account to join the conversation.
- FidoBoy
-
- Offline
- New Member
- Posts: 18
regards,
Please Log in or Create an account to join the conversation.
- Kristiyan Ivanchevski
-
- Offline
- Junior Member
- Posts: 23
fidoboy said:VERY interesting question, i'm also trying to experiment with different image sizes and i can't see how to accomplish this task. If you delete the cache folder contents, images are not rebuilt, so they are only generated when you add the article and then you can't change the page layout to see the effect of different image sizes. Also i'm not sure about how to change the image size parameters for a given category or the entire component, i've changed it on the category parameters but changes are not being reflected in the front end view... How can i change default image sizes? (small, medium, large, etc)
regards,
Please Log in or Create an account to join the conversation.
- FidoBoy
-
- Offline
- New Member
- Posts: 18
Kristiyan Ivanchevski said:You can do that bu changing the parameters in K2. But the problem here is how to rebuild already builded thumbnails with new sizes. If someone knows please tell or give a php...
fidoboy said:VERY interesting question, i'm also trying to experiment with different image sizes and i can't see how to accomplish this task. If you delete the cache folder contents, images are not rebuilt, so they are only generated when you add the article and then you can't change the page layout to see the effect of different image sizes. Also i'm not sure about how to change the image size parameters for a given category or the entire component, i've changed it on the category parameters but changes are not being reflected in the front end view... How can i change default image sizes? (small, medium, large, etc) regards,
Please Log in or Create an account to join the conversation.
- olsen
-
- Offline
- Elite Member
- Joomla and K2 Freelancer
Yeah, we know all that this is not the best way that how K2 should work but by now its how K2 is desing it.
What it can be done, if somebody wants to resize images without uploading them again, is get under cachefolder->size to resize all images, and change width, through any image software and then upload them again to the same folder.
rgds
Didn't solve your issues?? Why dont you consider hire me? Email me or contact me www.xevedigital.com for details
Please Log in or Create an account to join the conversation.
- Kristiyan Ivanchevski
-
- Offline
- Junior Member
- Posts: 23
olsen said:You can just resize and rebuild cache uploading again all images. Yeah, we know all that this is not the best way that how K2 should work but by now its how K2 is desing it.
What it can be done, if somebody wants to resize images without uploading them again, is get under cachefolder->size to resize all images, and change width, through any image software and then upload them again to the same folder.
rgds
Please Log in or Create an account to join the conversation.
- FidoBoy
-
- Offline
- New Member
- Posts: 18
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';
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';
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';
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';
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';
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';
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.
- Kristiyan Ivanchevski
-
- Offline
- Junior Member
- Posts: 23
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.
- olsen
-
- Offline
- Elite Member
- Joomla and K2 Freelancer
rgds
Didn't solve your issues?? Why dont you consider hire me? Email me or contact me www.xevedigital.com for details
Please Log in or Create an account to join the conversation.
- FidoBoy
-
- Offline
- New Member
- Posts: 18
Kristiyan Ivanchevski said:Thanks. Will try ASAP.
Please Log in or Create an account to join the conversation.
- Mick Hilliard
-
- Offline
- New Member
- Posts: 8
This would help my site development by allowing me to upload and work with the images I think I need, but later go back and optimize the photos (and reduce the file sizes) by processing locally and overwriting the images in the cache.
Please Log in or Create an account to join the conversation.
- Kristiyan Ivanchevski
-
- Offline
- Junior Member
- Posts: 23
Mick Hilliard said:I'm going to try this too, but I have a followup question: Is there a way to modify the image processing script to keep the original file name (instead of changing it to ffee2447b152494b43d9816faaea83c8_Generic.jpg)? It'd be easier to track my files if the image is renamed to picture_Generic.jpg.
This would help my site development by allowing me to upload and work with the images I think I need, but later go back and optimize the photos (and reduce the file sizes) by processing locally and overwriting the images in the cache.
Please Log in or Create an account to join the conversation.
- kath
-
- Offline
- New Member
- Posts: 7
i can't find that file. where exactly is items.php supposed to be?
thx a lot!
bob :)
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:
Please Log in or Create an account to join the conversation.
- kath
-
- Offline
- New Member
- Posts: 7
i can't find that file. where exactly is items.php supposed to be?
thx a lot!
bob :)
Please Log in or Create an account to join the conversation.
- kc
-
- Offline
- Senior Member
- Posts: 46
thanks
Please Log in or Create an account to join the conversation.