Skip to content

Instantly share code, notes, and snippets.

@matchaxnb
Created May 20, 2015 14:56
Show Gist options
  • Save matchaxnb/ecf52cf22a158dd70444 to your computer and use it in GitHub Desktop.
Save matchaxnb/ecf52cf22a158dd70444 to your computer and use it in GitHub Desktop.
Regenerate images in Prestashop from command line
<?php
define('_PS_ROOT_DIR_', '/path/to/prestashop/root');
define('_PS_ADMIN_DIR_', _PS_ROOT_DIR_.'admin_folder');
require(_PS_ADMIN_DIR_.'/../config/config.inc.php');
require(_PS_ADMIN_DIR_.'/functions.php');
class Employee2 extends EmployeeCore
{
public function isSuperAdmin()
{
return true;
}
public function isLoggedBack()
{
return true;
}
}
class AdminImagesController extends AdminImagesControllerCore
{
function regenerate()
{
$this->_regenerateThumbnails('all', true);
}
}
$context = Context::getContext();
$context->employee = new Employee2(1);
//print_r($context);
$aic = new AdminImagesController();
echo "Starting regeneration\n";
$aic->regenerate();
echo "Done regenerating\n";
?>
@Socrapop
Copy link

Socrapop commented Feb 19, 2021

Thank you for this snippet ! I was really bothered by Prestashop not having a native bulk thumbs regeneration for big ecommerce... You saved my day :)

@evgenij-sobolev, you have an error because you need to change the 2 first lines.
The first one needs to point to the root folder (from the location of your file).
Same thing for the admin folder, you have to rename it as it is in your prestashop install (admin123xyz...) ;)

@matchaxnb
Copy link
Author

I'm actually amazed this snippet still works after all these years. :)

@matteolavaggi
Copy link

Hi, thanks for the script any idea to limit the rgeneration process only to some product_id?

@falydev
Copy link

falydev commented Mar 24, 2021

@dev-4458
Copy link

@dkarvounaris
Copy link

dkarvounaris commented Oct 26, 2022

If you are gonna use this, and you gonna place it somewhere under your public_html/http_docs/whatever public folder accessible over http, you should add that bit on top of the script, as otherwise you may be introducing a security issue on your server:

if (php_sapi_name() !== 'cli') {
    die();
}

@PatriceVigier
Copy link

@PatriceVigier
Copy link

regenerate-images.php works on Prestashop 1.7.8.9
Thank you++++

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment