- Posts: 15920
COMMUNITY FORUM
[SOLVED] K2 image cache rebuild
- Krikor Boghossian
- Offline
- Platinum Member
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.
- dim
- Offline
- New Member
- Posts: 1
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
- Offline
- Platinum Member
- Posts: 15920
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.
- Cydonian
- Offline
- New Member
- Posts: 8
.
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);
}
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 <<<==
Please Log in or Create an account to join the conversation.
- Lee Tempest
- Offline
- New Member
- Posts: 13
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
- Offline
- Platinum Member
- Posts: 15920
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.
- Michael Yaeger
- Offline
- Premium Member
- Posts: 87
Please Log in or Create an account to join the conversation.
- Michael Yaeger
- Offline
- Premium Member
- Posts: 87
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?
Please Log in or Create an account to join the conversation.
- Michael Yaeger
- Offline
- Premium Member
- Posts: 87
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.