- Posts: 23
COMMUNITY FORUM
Image cache questions
- Kristiyan Ivanchevski
- Offline
- Junior Member
Less
More
14 years 6 months ago #72533
by Kristiyan Ivanchevski
Replied by Kristiyan Ivanchevski on topic Image cache questions
Yeah. Thanks. I think about that. And also, its better to store images into seperate folders, to prevent max listing (e.g. 1000 images in 6 sizes are 6000 images).
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
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
Less
More
- Posts: 18
14 years 6 months ago #72534
by FidoBoy
Replied by FidoBoy on topic Image cache questions
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,
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
Less
More
- Posts: 23
14 years 6 months ago #72535
by Kristiyan Ivanchevski
Replied by Kristiyan Ivanchevski on topic Image cache questions
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,
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
14 years 6 months ago #72536
by olsen
Didn't solve your issues?? Why dont you consider hire me? Email me or contact me www.xevedigital.com for details
Replied by olsen on topic Image cache questions
not tried but good job anyway
rgds
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
Less
More
- Posts: 18
14 years 5 months ago #72537
by FidoBoy
Replied by FidoBoy on topic Image cache questions
Have you tried it?
Kristiyan Ivanchevski said:Thanks. Will try ASAP.
Kristiyan Ivanchevski said:Thanks. Will try ASAP.
Please Log in or Create an account to join the conversation.
- Mick Hilliard
- Offline
- New Member
Less
More
- Posts: 8
14 years 5 months ago #72538
by Mick Hilliard
Replied by Mick Hilliard on topic Image cache questions
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.
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
Less
More
- Posts: 23
14 years 5 months ago #72539
by Kristiyan Ivanchevski
Replied by Kristiyan Ivanchevski on topic Image cache questions
But will make duplicate filenames.
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.
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
Less
More
- Posts: 7
14 years 3 months ago #72540
by kath
Replied by kath on topic Image cache questions
hi fidoboy,
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:
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
Less
More
- Posts: 7
14 years 3 months ago #72541
by kath
Replied by kath on topic Image cache questions
hi fidoboy,
i can't find that file. where exactly is items.php supposed to be?
thx a lot!
bob :)
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
Less
More
- Posts: 46
14 years 3 months ago #72542
by kc
Replied by kc on topic Image cache questions
same problem here, i used the above code snippet, which worked well but shouldn't K2 be able to just replace the image and clear the cache automatically w/o us have to clear the cache of all images?
thanks
thanks
Please Log in or Create an account to join the conversation.