- Posts: 21
COMMUNITY FORUM
[SOLVED] K2 image cache rebuild
- Dennis Miliopoulos
- Topic Author
- Offline
- Junior Member
I have a website with 6GB of cached k2 images. I need to transfer the website to another server and i want to delete k2 image cache, upload it and rebuild the cache on the new server.
Is that possible?
Thanks!
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
- Posts: 6218
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Dennis Miliopoulos
- Topic Author
- Offline
- Junior Member
- Posts: 21
Can i also exclude the sizes that i do not use (e.g small)?
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.
- Dennis Miliopoulos
- Topic Author
- Offline
- Junior Member
- Posts: 21
Please Log in or Create an account to join the conversation.
- Marcelo
- Offline
- New Member
- Posts: 1
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.
- skullmonkey
- Offline
- Junior Member
- Posts: 38
I have the exact same problem but I don't understand 2nd and 3rd line.
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)
What does this means? Run it from where?
I tried running it from the url as a path and it gets me to the github url.
Thanks,
S@
Please Log in or Create an account to join the conversation.
- George Tarantilis
- Offline
- New Member
- Posts: 2
Please Log in or Create an account to join the conversation.
- Voiceconnect Internet Solutions
- Offline
- Junior Member
- Posts: 39
This will then actually run the script - as they said, it takes a long time to run so make sure your max_execution_time = 6000 in your php.ini file is set high - i changed mine to 6000 for the test.
hope this helps someone like me that did not understand run it :woohoo:
oh - remember to change the sizes in the first part of the script to replicate your parameters and the quality setting - that is all you need to change.
<?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 <This email address is being protected from spambots. You need JavaScript enabled to view it.>
*/
// Variabels
$sizeG = 436;
$sizeL = 525;
$sizeM = 436;
$sizeS = 200;
$sizeXL = 900;
$sizeXS = 150;
$jpeg_quality = 75;
/**
* 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';
$sizes = array('Generic' => $sizeG,'L' => $sizeL,'M' => $sizeM,'S' => $sizeS,'XL' => $sizeXL,'XS' => $sizeXS);
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=70)
{
$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=70)
{
$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);
}
Please Log in or Create an account to join the conversation.