test
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • marcunix Friend
    #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 Friend
    #380102

    It’s just cached data. So you can delete all of files in this folder

    marcunix Friend
    #380110

    I just delete all files, but i have a problem, all images in k2 articles are missing and do not show it

    teletrance Friend
    #380112

    A new refresh of page, strating with Home, shoud bring back your images 🙂

    marcunix Friend
    #380114

    no, 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 Friend
    #380234

    Hello 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.

    marcunix Friend
    #381324

    i’ll test, thanks

    Phill Moderator
    #381326

    This 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.

Viewing 8 posts - 1 through 8 (of 8 total)

This topic contains 8 replies, has 5 voices, and was last updated by  Phill 13 years, 9 months ago.

We moved to new unified forum. Please post all new support queries in our New Forum