-
AuthorPosts
-
March 7, 2011 at 2:23 am #161104
I have in /media/k2/items/cache of TELINE IV so much images that i want to deleted. Can i to do it? or this content is necessary?
Thanks
khoand Friendkhoand
- Join date:
- February 2011
- Posts:
- 4500
- Downloads:
- 0
- Uploads:
- 179
- Thanks:
- 169
- Thanked:
- 1166 times in 1060 posts
March 7, 2011 at 5:29 pm #380102It’s just cached data. So you can delete all of files in this folder
March 7, 2011 at 6:24 pm #380110I just delete all files, but i have a problem, all images in k2 articles are missing and do not show it
teletrance Friendteletrance
- Join date:
- July 2008
- Posts:
- 110
- Downloads:
- 0
- Uploads:
- 10
- Thanks:
- 11
- Thanked:
- 8 times in 1 posts
March 7, 2011 at 6:50 pm #380112A new refresh of page, strating with Home, shoud bring back your images 🙂
March 7, 2011 at 7:01 pm #380114no, the images do not appear, i just refresh some times and images are missing totally, i have restore the last backup for recover that images, then the content inside of folder is neccesary
huypl Friendhuypl
- Join date:
- February 2011
- Posts:
- 162
- Downloads:
- 0
- Uploads:
- 1
- Thanks:
- 2
- Thanked:
- 20 times in 20 posts
March 8, 2011 at 8:23 am #380234Hello marcunix,
Yes you’re right marcunix. I also try to delete the imges in cache folder and then the images don’t appear in the frontpage. I discover that the first image in cache folder which the file name includes ‘Generic’ is necessary to show the images in the front page. The rest of the images are necessary for showing the images in the back end when you want to edit the article. So you can’t delete these images.March 14, 2011 at 10:07 pm #381324i’ll test, thanks
Phill ModeratorPhill
- Join date:
- February 2014
- Posts:
- 7013
- Downloads:
- 40
- Uploads:
- 77
- Thanks:
- 917
- Thanked:
- 2206 times in 1818 posts
March 14, 2011 at 10:51 pm #381326This cache file should not have been deleted. It is not a cache file in the true sense but a folder for resized images to reside. Unfortunately K2 only builds these images first time you upload them It does not perform any checks as to whether you want anything resized to replace each image nor does it check to see if the files are still there and rebuild them if required. I suppose this was to save on server load but it does seem to just be a pain. I found the below script for you but as I do not use K2 I have not tried it myself. If it does not work then you will have to ask the same question on the K2 forums as we can really only provide support on the template side that JA have build for K2.
Well, finally i’ve created a patch to allow image cache reconstruction from sources using current image size parameters. You must open the file /components/com_k2/models/item.php. Locate the function prepareItem and then into this function, locate the following lines:
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';
}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).
This script is not very resource friendly so once you have re-built all the images in your cache folder please restore the file to its original code.
-
AuthorPosts
This topic contains 8 replies, has 5 voices, and was last updated by Phill 13 years, 8 months ago.
We moved to new unified forum. Please post all new support queries in our New Forum