Keyword

[SOLVED] K2 image cache rebuild

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 7 months ago #119737 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 image cache rebuild
Kudos bossies :)

Remember to remove the file after you 've run to minimise the risk of someone executing it without your consent and depleting your server's resources.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
9 years 5 months ago #119738 by dim
Replied by dim on topic Re: K2 image cache rebuild
Guys I tried to use this, but I am getting an internal server error.
the php page looks incomplete or corrupted in several places... Any input on this?

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 5 months ago #119739 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 image cache rebuild
Hello Dim,

This extension was not developed by us, so you should post this issue on the extensions github page.

You can set the error reporting to maximum and paste ant errors here, to see if we can assist you.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
9 years 1 month ago - 9 years 1 month ago #142023 by Cydonian
Replied by Cydonian on topic [SOLVED] K2 image cache rebuild
Robert Deutz's cache rebuilder tool: github.com/rdeutz/rebuildK2imageCache is working pretty good and it has helped me a lot.
.
Since I have more than 1000 items having an image in my K2 web site, K2 produces 1000x6 (_Generic.jpg, _XS.jpg, _S.jpg, _M.jpg, _L.jpg, _XL.jpg for each main image of each K2 item) different resized images in total, I ended up with 6000 images and since there is a 2000-file limit for each folder (in this case, it is /media/k2/items/cache/ folder) on my hosting service, I had to divide the cache folder into 6 subfolders to keep 6000 K2 images.
So I created these, folders with ftp software on my hosting :
/media/k2/items/cache/Generic/ ( to create 1000 _Generic.jpg images under this folder)
/media/k2/items/cache/XS/ ( to create 1000 _XS.jpg images under this folder)
/media/k2/items/cache/S/ ( to create 1000 _S.jpg images under this folder)
/media/k2/items/cache/M/ ( to create 1000 _M.jpg images under this folder)
/media/k2/items/cache/L/ ( to create 1000 _L.jpg images under this folder)
/media/k2/items/cache/XL/ ( to create 1000 _XL.jpg images under this folder)

So I uploaded rebuild.php to /media/k2/items/ folder and run it by typing www.mysite.com/media/k2/items/rebuild.php on my browser's address bar and it displayed a 113 lines code so I copy and pasted that 113 lines code to notepad++ and changed code to produce 1000 of _Generic.jpg images under /media/k2/items/cache/Generic/ from 1000 source images under /media/k2/items/src/
Here is the changed code of of 113 lines to produce it:
<?php
/**
* How to use:
*
* 1) Copy this file as rebuild.php into "JPATH_ROOT/media/k2/items"
* 2) Check Variables, use a size of 0 for not processing this image size
* 3) run it "php -f rebuild.php" (it overwrites existing files without notice)
*
* @author Robert Deutz <[email protected]>
*/
// Variabels
$sizeG = 300;
$sizeL = 600;
$sizeM = 300;
$sizeS = 200;
$sizeXL = 900;
$sizeXS = 100;
$jpeg_quality = 90;
/**
* DO NOT CHANGE ANYTHING AFTER THIS LINE IF YOU DON'T KNOW WHAT YOU ARE DOING!
*/
$uploadclassfile = dirname(__FILE__).'/../../../administrator/components/com_k2/lib/class.upload.php';
if(!file_exists($uploadclassfile))
{
echo "Can't find class.upload.php! Is K2 installed? Did you copy rebuild.php to the right directory?";
}
define('_JEXEC',1);
require_once ($uploadclassfile);
// dirs
$sourcedir = dirname(__FILE__).'/src';
$targetdir = dirname(__FILE__).'/cache/Generic/';
$sizes = array('Generic' => $sizeG);
if ($fhandle = opendir($sourcedir)) {
while (false !== ($entry = readdir($fhandle)))
{
$file = $sourcedir.'/'.$entry;
if (is_file($file))
{
echo '.';
$r = buildImages($file, $targetdir, $sizes, $jpeg_quality);
if ($r === true)
{
echo "File: ".$entry . " SUCCESSFUL\n";
}
else
{
echo "File: ".$entry . " FAIL\n";
echo "Details:\n";
foreach($sizes AS $key => $value)
{
$result = 'Success';
if (array_key_exists($key, $r))
{
$result = 'Failed';
}
echo "Size $key ($value px): ".$result."\n";
}
}
}
}
closedir($fhandle);
}
function buildImages($sourcefile, $targetdir, $sizes, $jpeg_quality=90)
{
$resultsummery = true;
foreach($sizes AS $key => $value)
{
if ($value != 0)
{
$filename = basename($sourcefile,'.jpg');
$targetfile = $targetdir.'/'.$filename.'_'.$key.'.jpg';
if (buildImage($sourcefile, $targetfile, $value) !== true)
{
// Successful
$resultdetails[$key] = true;
}
else
{
// Failed
$resultsummery = false;
$resultdetails[$key] = false;
}
}
}
return $resultsummery ? true : $resultdetails;
}
function buildImage($sourcefile, $targetfile, $size, $jpeg_quality=90)
{
$handle = new Upload($sourcefile);
$savepath = dirname($targetfile);
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'jpg';
$handle->jpeg_quality = $jpeg_quality;
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = basename($targetfile,'.jpg');
$handle->image_x = (int) $size;
return $handle->Process($savepath);
}
saved it as rebuild_generic.php and uploaded it to /media/k2/items/ and ran it by typing www.mysite.com/media/k2/items/rebuild_generic.php on my browser's address bar. If your PHP variable limits are not enough to run this code from browser's address bar, then you should login to your hosting by SSH and go to the folder yourwebsiteroot/media/k2/items/ by using unix commands "cd media" or "ls" etc. then you should run "rebuild_generic.php" by typing "php -f rebuild.php" (rebuild_generic.php in my case). I created 5 other php files from rebuild_generic.php by changing relevant lines of code in it and by saving them as rebuild_generic.php, rebuild_XS.php, rebuild_S.php etc. Then I ran each to generate 1000 XS images, 1000 S images etc. under relevant directories I mentioned above.
This solved my 2000 image limit problem of /media/k2/items/cache/ folder for now.

I also had to change some other php files like:
/administrator/components/com_k2/views/items/tmpl => default.php
line 167 => added .DS.'XL'
line 168 => added XL/
so that admin can view image of an item when he edits a previously written item because it has a new location now.
because item's old image location was: /media/k2/items/cache/
and now item's new image location is: /media/k2/items/cache/XL/

I just wanted to show you how to use rebuild.php in details when you faced a "2000 file limit" for "item image cache" folder.
I hope it helps!

P.S.: ==>>> K2 developers should find a permanent solution for big web sites including thousands of items and thousands of item images created under /media/k2/items/cache/ folder in next releases of K2 <<<==
Last edit: 9 years 1 month ago by Cydonian. Reason: correction

Please Log in or Create an account to join the conversation.

More
7 years 4 months ago #159602 by Lee Tempest
Replied by Lee Tempest on topic [SOLVED] K2 image cache rebuild
Hello,
Could you please post the modified files you create to do the individual sizes?

I've tried running the rebuild file from my browser and it generates a new folder called Generic in the cache folder, but does not seem to overwrite the existing md5 files found in the cache folder, how can I replace these?

I really hope the JoomlaWorks team look at integrating a cache rebuild into the next K2 release.

Thanks.

Lee

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 4 months ago #159611 by Krikor Boghossian
Replied by Krikor Boghossian on topic [SOLVED] K2 image cache rebuild
As a plugin it is worth considering.

As a built in feature, that would be really REALLY dangerous. Most sites run into underpowered servers. I can see servers crashing down and us getting all the blame.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
7 years 4 months ago #159727 by Michael Yaeger
Replied by Michael Yaeger on topic [SOLVED] K2 image cache rebuild
We've added watermarks to all images in the site and replaced them on the server. However, K2 items do not display the updated images. Is running the above mentioned script required?

Please Log in or Create an account to join the conversation.

More
7 years 4 months ago - 7 years 4 months ago #159728 by Michael Yaeger
Replied by Michael Yaeger on topic [SOLVED] K2 image cache rebuild

Krikor wrote: As a plugin it is worth considering.

@joomlaworks wrote: @antonydoyle Not really, but we do plan to launch a plugin soon to do just that, provided the source images are kept intact ;)


Invalid consumer key/secret in configuration

No progress on said plugin in the last 4 years?
Last edit: 7 years 4 months ago by Michael Yaeger.

Please Log in or Create an account to join the conversation.

More
7 years 4 months ago #159739 by Michael Yaeger
Replied by Michael Yaeger on topic [SOLVED] K2 image cache rebuild
I'm, also, noticing that none of the category images are using the newly uploaded images, either.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 4 months ago #159761 by Krikor Boghossian
Replied by Krikor Boghossian on topic [SOLVED] K2 image cache rebuild
I do no think that this script resizes the category images.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum