Keyword

[SOLVED] K2 image cache rebuild

  • Dennis Miliopoulos
  • Dennis Miliopoulos's Avatar Topic Author
  • Offline
  • Junior Member
More
10 years 5 months ago #119727 by Dennis Miliopoulos
[SOLVED] K2 image cache rebuild was created by Dennis Miliopoulos
Hello everyone,

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.

More
10 years 4 months ago #119728 by JoomlaWorks
Replied by JoomlaWorks on topic Re: K2 image cache rebuild
Robert Deutz has created this cache rebuilder tool: github.com/rdeutz/rebuildK2imageCache

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
  • Dennis Miliopoulos's Avatar Topic Author
  • Offline
  • Junior Member
More
10 years 4 months ago #119729 by Dennis Miliopoulos
Replied by Dennis Miliopoulos on topic Re: K2 image cache rebuild
Thank you for the reply,

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 4 months ago #119730 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 image cache rebuild
Yes, in the direction is says: Check Variables, use a size of 0 for not processing this image size

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
  • Dennis Miliopoulos's Avatar Topic Author
  • Offline
  • Junior Member
More
10 years 4 months ago #119731 by Dennis Miliopoulos
Replied by Dennis Miliopoulos on topic Re: K2 image cache rebuild
thank you!

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

More
10 years 4 months ago #119732 by Marcelo
Replied by Marcelo on topic Re: K2 image cache rebuild
Hi I've tried this but only works for the first 70 images... any idea why am i doing wrong.. or how can make it work for all the images. I have 600 images in total.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 4 months ago #119733 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 image cache rebuild
Are you sure you are not experiencing PHP Memory limit issues?

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

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

More
10 years 2 months ago #119734 by skullmonkey
Replied by skullmonkey on topic Re: K2 image cache rebuild
Hello,
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.

More
10 years 1 week ago #119735 by George Tarantilis
Replied by George Tarantilis on topic Re: K2 image cache rebuild
Can I run this tool in the remote web server, or only if I have SSH access to it in order to use the php command line?

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

  • Voiceconnect Internet Solutions
  • Voiceconnect Internet Solutions's Avatar
  • Offline
  • Junior Member
More
9 years 6 months ago - 9 years 6 months ago #119736 by Voiceconnect Internet Solutions
Replied by Voiceconnect Internet Solutions on topic Re: K2 image cache rebuild
ok so - have figured this out being also a non developer. The file they have you downloaded is a html sort of file actually and not a real php file - below is the php part - copy this and paste in new file and save as rebuild.php - then to run it, just open it on your web server by just adding /media/k2/items/rebuild.php after your url like localhost/testsite/media/k2/items/rebuild.php

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.


Powered by Kunena Forum