gabrielchiron Posted February 11, 2015 Share Posted February 11, 2015 (edited) Buenas a todos estoy haciendo un módulo y cuando le pongo imágenes al producto lo hace pero me encuentro con el problema de que no genera todos los tamaños de imagen y tengo que regenerar miniaturas desde el backoffice, en local no me supone nada pero en la tienda tengo 5mil productos y es un proceso que tarda bastante. Sabeis si se puede regenerar X productos solo o como generar bien las imágenes y no solo algunas?? Os paso mis funciones por si estubieran mal: //Imagenes $subdir =_PS_MODULE_DIR_.'Excelport/uploads/img/'; for ($i=1; $i < 10; $i++) { $file = $object->reference.'_'.$i.'.jpg'; $url = $subdir.$file; if (file_exists($subdir.$file)){ $shops = Shop::getShops(true, null, true); $image = new Image(); $image->id_product = (int)$object->id; $image->position = Image::getHighestPosition($object->id) + 1; if ($i == 1) { $image->cover = true; }else{ $image->cover = false; } if (($image->validateFields(false, true)) === true && ($image->validateFieldsLang(false, true)) === true && $image->add()) { $image->associateTo($shops); if (!self::copyImg($id_product, $image->id, $url, 'products', false)) { $image->delete(); } } } } Y la función: protected static function copyImg($id_entity, $id_image = null, $url, $entity = 'products', $regenerate = true) { $tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'ps_import'); $watermark_types = explode(',', Configuration::get('WATERMARK_TYPES')); switch ($entity) { default: case 'products': $image_obj = new Image($id_image); $path = $image_obj->getPathForCreation(); break; case 'categories': $path = _PS_CAT_IMG_DIR_.(int)$id_entity; break; case 'manufacturers': $path = _PS_MANU_IMG_DIR_.(int)$id_entity; break; case 'suppliers': $path = _PS_SUPP_IMG_DIR_.(int)$id_entity; break; } $url = str_replace(' ', '%20', trim($url)); // Evaluate the memory required to resize the image: if it's too much, you can't resize it. if (!ImageManager::checkImageMemoryLimit($url)) return false; // 'file_exists' doesn't work on distant file, and getimagesize make the import slower. // Just hide the warning, the traitment will be the same. if (Tools::copy($url, $tmpfile)) { ImageManager::resize($tmpfile, $path.'.jpg'); $images_types = ImageType::getImagesTypes($entity); if ($regenerate) foreach ($images_types as $image_type) { ImageManager::resize($tmpfile, $path.'-'.stripslashes($image_type['name']).'.jpg', $image_type['width'], $image_type['height']); if (in_array($image_type['id_image_type'], $watermark_types)) Hook::exec('actionWatermark', array('id_image' => $id_image, 'id_product' => $id_entity)); } } else { unlink($tmpfile); return false; } unlink($tmpfile); return true; } Gracias de antemano y un saludo! Edited February 11, 2015 by gabrielchiron (see edit history) Link to comment Share on other sites More sharing options...
gabrielchiron Posted February 11, 2015 Author Share Posted February 11, 2015 Antes y lo pongo y antes lo sulciono jaja Le estaba pasando un false al regenerate ^^ if (!self::copyImg($id_product, $image->id, $url, 'products', true)) { $image->delete(); } Así se arregla Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now