- Posts: 663
COMMUNITY FORUM
Image cache questions
- BBC
-
- Offline
- Platinum Member
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.
- BBC
-
- Offline
- Platinum Member
- Posts: 663
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->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->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';
if (JRequest::getInt('itemImageXL')) {
$imageWidth = JRequest::getInt('itemImageXL');
} else {
$imageWidth = $params->get('itemImageXL', '800');
}
if (JRequest::getInt('itemImageXL_Height')) {
$imageHeight = JRequest::getInt('itemImageXL_Height');
} else {
$imageHeight = $params->get('itemImageXL_Height', '800');
}
$handle->image_x = $imageWidth;
$handle->image_y = $imageHeight;
$handle->image_ratio_y = true;
$handle->image_ratio_crop = true;break;
case 'large':
$handle->file_new_name_body = $srcImage.'_L';
if (JRequest::getInt('itemImageL')) {
$imageWidth = JRequest::getInt('itemImageL');
} else {
$imageWidth = $params->get('itemImageL', '600');
}
if (JRequest::getInt('itemImageL_Height')) {
$imageHeight = JRequest::getInt('itemImageL_Height');
} else {
$imageHeight = $params->get('itemImageL_Height', '600');
}
$handle->image_x = $imageWidth;
$handle->image_y = $imageHeight;
$handle->image_ratio_y = true;
$handle->image_ratio_crop = true;break;
case 'medium':
$handle->file_new_name_body = $srcImage.'_M';
if (JRequest::getInt('itemImageM')) {
$imageWidth = JRequest::getInt('itemImageM');
} else {
$imageWidth = $params->get('itemImageM', '400');
}
if (JRequest::getInt('itemImageM_Height')) {
$imageHeight = JRequest::getInt('itemImageM_Height');
} else {
$imageHeight = $params->get('itemImageM_Height', '400');
}
$handle->image_x = $imageWidth;
$handle->image_y = $imageHeight;
$handle->image_ratio_y = true;
$handle->image_ratio_crop = true;
break;
case 'small':
$handle->file_new_name_body = $srcImage.'_S';
if (JRequest::getInt('itemImageS')) {
$imageWidth = JRequest::getInt('itemImageS');
} else {
$imageWidth = $params->get('itemImageS', '200');
}
if (JRequest::getInt('itemImageS_Height')) {
$imageHeight = JRequest::getInt('itemImageS_Height');
} else {
$imageHeight = $params->get('itemImageS_Height', '200');
}
$handle->image_x = $imageWidth;
$handle->image_y = $imageHeight;
$handle->image_ratio_crop = true;
break;
case 'xsmall':
$handle->file_new_name_body = $srcImage.'_XS';
if (JRequest::getInt('itemImageXS')) {
$imageWidth = JRequest::getInt('itemImageXS');
} else {
$imageWidth = $params->get('itemImageXS', '100');
}
if (JRequest::getInt('itemImageXS_Height')) {
$imageHeight = JRequest::getInt('itemImageXS_Height');
} else {
$imageHeight = $params->get('itemImageXS_Height', '100');
}
$handle->image_x = $imageWidth;
$handle->image_y = $imageHeight;
$handle->image_ratio_crop = true;
break;
case 'generic':
$handle->file_new_name_body = $srcImage.'_Generic';
$imageWidth = $params->get('itemImageGeneric', '300');
$imageHeight = $params->get('itemImageGeneric_Height', '300');
$handle->image_x = $imageWidth;
$handle->image_y = $imageHeight;
$handle->image_ratio_crop = true;
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';
}
Please Log in or Create an account to join the conversation.
- BBC
-
- Offline
- Platinum Member
- Posts: 663
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.
- BBC
-
- Offline
- Platinum Member
- Posts: 663
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.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6229
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 <img> 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.
- BBC
-
- Offline
- Platinum Member
- Posts: 663
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.
- Ivaylo Cherkezov
-
- Offline
- New Member
- Posts: 4
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.
- BBC
-
- Offline
- Platinum Member
- Posts: 663
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.
- Ivaylo Cherkezov
-
- Offline
- New Member
- Posts: 4
Please Log in or Create an account to join the conversation.
- ansi.alpha
-
- Offline
- New Member
- Posts: 2
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.<?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! <br/>'; } 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);?>
Please Log in or Create an account to join the conversation.
- ansi.alpha
-
- Offline
- New Member
- Posts: 2
$imgname = $file; replace it with
$imgname = substr($file ,0 ,-4);
Please Log in or Create an account to join the conversation.
- B_Dark
-
- Offline
- Premium Member
- Posts: 126
ansi.alpha said:
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.<?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! <br/>'; } 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);?>
Please Log in or Create an account to join the conversation.
- Roberto Céparo
-
- Offline
- New Member
- Posts: 11
search imagejpeg ($ new_image, $ save);replace imagejpeg ($ new_image, $ save, 100);replace quality by the number of such quality they want. 100 or 75.I'm from Argentina and my site is www.vodok.com.ar and I served
Please Log in or Create an account to join the conversation.
- Russell English
-
- Offline
- Junior Member
- Posts: 37
Please Log in or Create an account to join the conversation.
- Russell English
-
- Offline
- Junior Member
- Posts: 37
In the end, I just removed all images (could do this as the images were only placeholder examples on a dev site) from /media/k2/items/cache and /media/k2/items/src
Please Log in or Create an account to join the conversation.
- shenkwen
-
- Offline
- Junior Member
- Posts: 30
Is there any official notes addressing this?
Please Log in or Create an account to join the conversation.
- Christos Kougkouleris
-
- Offline
- New Member
- Posts: 5
I have no problem with disk space so when is the problem created? with number of files in cache folder?
Because I created a folder e.g. was_cache and moved a couple hundred of images from cache in there and then the image tab worked again... and after some days the same problem and just moved some images and then again everything worked....
So my question is... if I do whichever of the two solutions with the coding hack, as I do not have space problem will my problem be fixed or is there something else?
Please help me, someone, on this as I do not know where to look at...
Thank you in advance
Please Log in or Create an account to join the conversation.
- BBC
-
- Offline
- Platinum Member
- Posts: 663
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
I think this code is a bit outdated. You can simply turn on the Force 'item modified date' as URL timestamp on image paths options on the advanced settings of K2. That way you won't need to clear the cache.
Please Log in or Create an account to join the conversation.
- BBC
-
- Offline
- Platinum Member
- Posts: 663
Krikor Boghossian wrote: Hello there,
I think this code is a bit outdated. You can simply turn on the Force 'item modified date' as URL timestamp on image paths options on the advanced settings of K2. That way you won't need to clear the cache.
Please stop spreading misinformations, this wont clean junk from disk. And decide for once if it will be image cache rebuild plugin, or not. It is your script, your own decision, but dont pull peoples legs.
Is there a way to rebuild the #K2 image cache easily? I think I've done and done something daft... #joomla
Reply Retweet Favorite More
1
Retweet
10:57 AM - 8 Sep 12
JoomlaWorks @joomlaworks 11 Sep
@antonydoyle Not really, but we do plan to launch a plugin soon to do just that, provided the source images are kept intact ;)
Details
1
Retweet
7:29 AM - 11 Sep 12 · Details
Please Log in or Create an account to join the conversation.