예제 #1
0
파일: ImageType.php 프로젝트: yiuked/tmcart
 public function reloadImages()
 {
     $dir = _TM_PRO_IMG_DIR;
     $productsImages = Image::getAllImages();
     foreach ($productsImages as $k => $image) {
         $imageObj = new Image($image['id_image']);
         //echo $dir.$imageObj->getExistingImgPath().'.jpg';
         if (file_exists($dir . $imageObj->getExistingImgPath() . '.jpg')) {
             if (!ImageCore::imageResize($dir . $imageObj->getExistingImgPath() . '.jpg', $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($this->name) . '.jpg', (int) $this->width, (int) $this->height)) {
                 $errors = true;
             }
         }
     }
 }
예제 #2
0
    /**
     * Delete resized image then regenerate new one with updated settings
     */
    private function _regenerateThumbnails()
    {
        @ini_set('max_execution_time', 3600);
        $productsTypes = ImageType::getImagesTypes('products');
        $categoriesTypes = ImageType::getImagesTypes('categories');
        $languages = Language::getLanguages();
        $productsImages = Image::getAllImages();
        /* Delete categories images */
        $toDel = scandir(_PS_CAT_IMG_DIR_);
        foreach ($toDel as $d) {
            if (preg_match('/^[0-9]+\\-(.*)\\.jpg$/', $d) or preg_match('/^([[:lower:]]{2})\\-default\\-(.*)\\.jpg$/', $d)) {
                unlink(_PS_CAT_IMG_DIR_ . $d);
            }
        }
        /* Regenerate categories images */
        $errors = false;
        $categoriesImages = scandir(_PS_CAT_IMG_DIR_);
        foreach ($categoriesImages as $image) {
            if (preg_match('/^[0-9]*\\.jpg$/', $image)) {
                foreach ($categoriesTypes as $k => $imageType) {
                    if (!imageResize(_PS_CAT_IMG_DIR_ . $image, _PS_CAT_IMG_DIR_ . substr($image, 0, -4) . '-' . stripslashes($imageType['name']) . '.jpg', intval($imageType['width']), intval($imageType['height']))) {
                        $errors = true;
                    }
                }
            }
        }
        if ($errors) {
            $this->_errors[] = Tools::displayError('Cannot write category image. Please check the folder\'s writing permissions.');
        }
        /* Regenerate No-picture images */
        $errors = false;
        foreach ($categoriesTypes as $k => $imageType) {
            foreach ($languages as $language) {
                $file = _PS_CAT_IMG_DIR_ . $language['iso_code'] . '.jpg';
                if (!file_exists($file)) {
                    $file = _PS_PROD_IMG_DIR_ . Language::getIsoById(intval(Configuration::get('PS_LANG_DEFAULT'))) . '.jpg';
                }
                if (!imageResize($file, _PS_CAT_IMG_DIR_ . $language['iso_code'] . '-default-' . stripslashes($imageType['name']) . '.jpg', intval($imageType['width']), intval($imageType['height']))) {
                    $errors = true;
                }
            }
        }
        if ($errors) {
            $this->_errors[] = Tools::displayError('Cannot write no-picture image to the category images folder. Please check the folder\'s writing permissions.');
        }
        /* Delete manufacturers images */
        $toDel = scandir(_PS_MANU_IMG_DIR_);
        foreach ($toDel as $d) {
            if (preg_match('/^[0-9]+\\-(.*)\\.jpg$/', $d) or preg_match('/^([[:lower:]]{2})\\-default\\-(.*)\\.jpg$/', $d)) {
                unlink(_PS_MANU_IMG_DIR_ . $d);
            }
        }
        /* Regenerate manufacturers images */
        $manufacturersTypes = ImageType::getImagesTypes('manufacturers');
        $manufacturersImages = scandir(_PS_MANU_IMG_DIR_);
        $errors = false;
        foreach ($manufacturersImages as $image) {
            if (preg_match('/^[0-9]*\\.jpg$/', $image)) {
                foreach ($manufacturersTypes as $k => $imageType) {
                    if (!imageResize(_PS_MANU_IMG_DIR_ . $image, _PS_MANU_IMG_DIR_ . substr($image, 0, -4) . '-' . stripslashes($imageType['name']) . '.jpg', intval($imageType['width']), intval($imageType['height']))) {
                        $errors = true;
                    }
                }
            }
        }
        if ($errors) {
            $this->_errors[] = Tools::displayError('Cannot write manufacturer images. Please check the folder\'s writing permissions.');
        }
        /* Regenerate No-picture images */
        $errors = false;
        foreach ($manufacturersTypes as $k => $imageType) {
            foreach ($languages as $language) {
                $file = _PS_MANU_IMG_DIR_ . $language['iso_code'] . '.jpg';
                if (!file_exists($file)) {
                    $file = _PS_PROD_IMG_DIR_ . Language::getIsoById(intval(Configuration::get('PS_LANG_DEFAULT'))) . '.jpg';
                }
                if (!imageResize($file, _PS_MANU_IMG_DIR_ . $language['iso_code'] . '-default-' . stripslashes($imageType['name']) . '.jpg', intval($imageType['width']), intval($imageType['height']))) {
                    $errors = true;
                }
            }
        }
        if ($errors) {
            $this->_errors[] = Tools::displayError('Cannot write no-picture image to the manufacturer images folder. Please check the folder\'s writing permissions.');
        }
        /* Delete suppliers images */
        $toDel = scandir(_PS_SUPP_IMG_DIR_);
        foreach ($toDel as $d) {
            if (preg_match('/^[0-9]+\\-(.*)\\.jpg$/', $d) or preg_match('/^([[:lower:]]{2})\\-default\\-(.*)\\.jpg$/', $d)) {
                unlink(_PS_SUPP_IMG_DIR_ . $d);
            }
        }
        /* Regenerate suppliers images */
        $suppliersTypes = ImageType::getImagesTypes('suppliers');
        $suppliersImages = scandir(_PS_SUPP_IMG_DIR_);
        $errors = false;
        foreach ($suppliersImages as $image) {
            if (preg_match('/^[0-9]*\\.jpg$/', $image)) {
                foreach ($suppliersTypes as $k => $imageType) {
                    if (!imageResize(_PS_SUPP_IMG_DIR_ . $image, _PS_SUPP_IMG_DIR_ . substr($image, 0, -4) . '-' . stripslashes($imageType['name']) . '.jpg', intval($imageType['width']), intval($imageType['height']))) {
                        $errors = true;
                    }
                }
            }
        }
        if ($errors) {
            $this->_errors[] = Tools::displayError('Cannot write supplier images into the supplier images folder. Please check the folder\'s writing permissions.');
        }
        /* Regenerate No-picture images */
        $errors = false;
        foreach ($suppliersTypes as $k => $imageType) {
            foreach ($languages as $language) {
                $file = _PS_SUPP_IMG_DIR_ . $language['iso_code'] . '.jpg';
                if (!file_exists($file)) {
                    $file = _PS_PROD_IMG_DIR_ . Language::getIsoById(intval(Configuration::get('PS_LANG_DEFAULT'))) . '.jpg';
                }
                if (!imageResize($file, _PS_SUPP_IMG_DIR_ . $language['iso_code'] . '-default-' . stripslashes($imageType['name']) . '.jpg', intval($imageType['width']), intval($imageType['height']))) {
                    $errors = true;
                }
            }
        }
        if ($errors) {
            $this->_errors[] = Tools::displayError('Cannot write no-picture image into the suppliers images folder.<br />Please check its writing permissions.');
        }
        /* Delete scenes images */
        $toDel = scandir(_PS_SCENE_IMG_DIR_);
        foreach ($toDel as $d) {
            if (preg_match('/^[0-9]+\\-(.*)\\.jpg$/', $d) or preg_match('/^([[:lower:]]{2})\\-default\\-(.*)\\.jpg$/', $d)) {
                unlink(_PS_SCENE_IMG_DIR_ . $d);
            }
        }
        /* Regenerate scenes images */
        $scenesTypes = ImageType::getImagesTypes('scenes');
        $scenesImages = scandir(_PS_SCENE_IMG_DIR_);
        $errors = false;
        foreach ($scenesImages as $image) {
            if (preg_match('/^[0-9]*\\.jpg$/', $image)) {
                foreach ($scenesTypes as $k => $imageType) {
                    if (!imageResize(_PS_SCENE_IMG_DIR_ . $image, _PS_SCENE_IMG_DIR_ . substr($image, 0, -4) . '-' . stripslashes($imageType['name']) . '.jpg', intval($imageType['width']), intval($imageType['height']))) {
                        $errors = true;
                    }
                }
            }
        }
        if ($errors) {
            $this->_errors[] = Tools::displayError('Cannot write scene images into the scene images folder. Please check the folder\'s writing permissions.');
        }
        /* Regenerate No-picture images */
        $errors = false;
        foreach ($scenesTypes as $k => $imageType) {
            foreach ($languages as $language) {
                $file = _PS_SCENE_IMG_DIR_ . $language['iso_code'] . '.jpg';
                if (!file_exists($file)) {
                    $file = _PS_PROD_IMG_DIR_ . Language::getIsoById(intval(Configuration::get('PS_LANG_DEFAULT'))) . '.jpg';
                }
                if (!imageResize($file, _PS_SCENE_IMG_DIR_ . $language['iso_code'] . '-default-' . stripslashes($imageType['name']) . '.jpg', intval($imageType['width']), intval($imageType['height']))) {
                    $errors = true;
                }
            }
        }
        if ($errors) {
            $this->_errors[] = Tools::displayError('Cannot write no-picture image into the scenes images folder.<br />Please check its writing permissions.');
        }
        /* Delete products images */
        $toDel = scandir(_PS_PROD_IMG_DIR_);
        foreach ($toDel as $d) {
            if (preg_match('/^[0-9]+\\-[0-9]+\\-(.*)\\.jpg$/', $d) or preg_match('/^([[:lower:]]{2})\\-default\\-(.*)\\.jpg$/', $d)) {
                unlink(_PS_PROD_IMG_DIR_ . $d);
            }
        }
        /* Regenerate No-picture images */
        $errors = false;
        foreach ($productsTypes as $k => $imageType) {
            foreach ($languages as $language) {
                $file = _PS_PROD_IMG_DIR_ . $language['iso_code'] . '.jpg';
                if (!file_exists($file)) {
                    $file = _PS_PROD_IMG_DIR_ . Language::getIsoById(intval(Configuration::get('PS_LANG_DEFAULT'))) . '.jpg';
                }
                $newFile = _PS_PROD_IMG_DIR_ . $language['iso_code'] . '-default-' . stripslashes($imageType['name']) . '.jpg';
                if (!imageResize($file, $newFile, intval($imageType['width']), intval($imageType['height']))) {
                    $errors = true;
                }
            }
        }
        if ($errors) {
            $this->_errors[] = Tools::displayError('Cannot write no-picture image to the product images folder. Please check the folder\'s writing permissions.');
        }
        /* Regenerate products images */
        $errors = false;
        foreach ($productsImages as $k => $image) {
            if (file_exists(_PS_PROD_IMG_DIR_ . $image['id_product'] . '-' . $image['id_image'] . '.jpg')) {
                foreach ($productsTypes as $k => $imageType) {
                    $newFile = _PS_PROD_IMG_DIR_ . $image['id_product'] . '-' . $image['id_image'] . '-' . stripslashes($imageType['name']) . '.jpg';
                    if (!imageResize(_PS_PROD_IMG_DIR_ . $image['id_product'] . '-' . $image['id_image'] . '.jpg', $newFile, intval($imageType['width']), intval($imageType['height']))) {
                        $errors = true;
                    }
                }
            }
        }
        // Hook watermark optimization
        $result = Db::getInstance()->ExecuteS('
		SELECT m.`name` FROM `' . _DB_PREFIX_ . 'module` m
		LEFT JOIN `' . _DB_PREFIX_ . 'hook_module` hm ON hm.`id_module` = m.`id_module`
		LEFT JOIN `' . _DB_PREFIX_ . 'hook` h ON hm.`id_hook` = h.`id_hook`
		WHERE h.`name` = \'watermark\' AND m.`active` = 1');
        if ($result and sizeof($result)) {
            foreach ($productsImages as $k => $image) {
                if (file_exists(_PS_PROD_IMG_DIR_ . $image['id_product'] . '-' . $image['id_image'] . '.jpg')) {
                    foreach ($result as $k => $module) {
                        if ($moduleInstance = Module::getInstanceByName($module['name']) and is_callable(array($moduleInstance, 'hookwatermark'))) {
                            call_user_func(array($moduleInstance, 'hookwatermark'), array('id_image' => $image['id_image'], 'id_product' => $image['id_product']));
                        }
                    }
                }
            }
        }
        if ($errors) {
            $this->_errors[] = Tools::displayError('Cannot write product image. Please check the folder\'s writing permissions.');
        }
        return sizeof($this->_errors) > 0 ? false : true;
    }
예제 #3
0
 /**
  * ONLY FOR DEVELOPMENT PURPOSE
  */
 public function backupImageImage()
 {
     $types = array();
     foreach (ImageType::getImagesTypes('products') as $type) {
         $types[] = $type['name'];
     }
     $backup_path = $this->img_path . 'p/';
     $from_path = _PS_PROD_IMG_DIR_;
     if (!is_dir($backup_path) && !mkdir($backup_path)) {
         $this->setError(sprintf('Cannot create directory <i>%s</i>', $backup_path));
     }
     foreach (Image::getAllImages() as $image) {
         $image = new Image($image['id_image']);
         $image_path = $image->getExistingImgPath();
         if (file_exists($from_path . $image_path . '.' . $image->image_format)) {
             copy($from_path . $image_path . '.' . $image->image_format, $backup_path . $this->generateId('image', $image->id) . '.' . $image->image_format);
         }
         foreach ($types as $type) {
             if (file_exists($from_path . $image_path . '-' . $type . '.' . $image->image_format)) {
                 copy($from_path . $image_path . '-' . $type . '.' . $image->image_format, $backup_path . $this->generateId('image', $image->id) . '-' . $type . '.' . $image->image_format);
             }
         }
     }
 }
 protected function manageListDeclinatedImages($directory, $normal_image_sizes)
 {
     // Check if method is allowed
     if ($this->wsObject->method != 'GET') {
         throw new WebserviceException('This method is not allowed for listing category images.', array(55, 405));
     }
     $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image_types', array());
     foreach ($normal_image_sizes as $image_size) {
         $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image_type', array(), array('id' => $image_size['id_image_type'], 'name' => $image_size['name'], 'xlink_resource' => $this->wsObject->wsUrl . 'image_types/' . $image_size['id_image_type']), false);
     }
     $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('image_types', array());
     $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('images', array());
     if ($this->imageType == 'products') {
         $ids = array();
         $images = Image::getAllImages();
         foreach ($images as $image) {
             $ids[] = $image['id_product'];
         }
         $ids = array_unique($ids, SORT_NUMERIC);
         asort($ids);
         foreach ($ids as $id) {
             $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image', array(), array('id' => $id, 'xlink_resource' => $this->wsObject->wsUrl . 'images/' . $this->imageType . '/' . $id), false);
         }
     } else {
         $nodes = scandir($directory);
         foreach ($nodes as $node) {
             // avoid too much preg_match...
             if ($node != '.' && $node != '..' && $node != '.svn') {
                 if ($this->imageType != 'products') {
                     preg_match('/^(\\d+)\\.jpg*$/Ui', $node, $matches);
                     if (isset($matches[1])) {
                         $id = $matches[1];
                         $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image', array(), array('id' => $id, 'xlink_resource' => $this->wsObject->wsUrl . 'images/' . $this->imageType . '/' . $id), false);
                     }
                 }
             }
         }
     }
     $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('images', array());
     return true;
 }
예제 #5
0
<?php

/* Inclusion de la classe Image pour la récupération des données de la base */
require_once "php/model/Image.php";
/* Inclusion de la classe User pour la récupération des données de la base */
require_once "php/model/User.php";
/* Inclusion du fichier de connexion à la BD */
include_once "php/controller/connect-bd.php";
$images = new Image($bdd);
$data_img = $images->getAllImages();
예제 #6
0
    private function _regenerateWatermark($dir)
    {
        $result = Db::getInstance()->ExecuteS('
			SELECT m.`name` FROM `' . _DB_PREFIX_ . 'module` m
			LEFT JOIN `' . _DB_PREFIX_ . 'hook_module` hm ON hm.`id_module` = m.`id_module`
			LEFT JOIN `' . _DB_PREFIX_ . 'hook` h ON hm.`id_hook` = h.`id_hook`
			WHERE h.`name` = \'watermark\' AND m.`active` = 1');
        if ($result and sizeof($result)) {
            $productsImages = Image::getAllImages();
            foreach ($productsImages as $k => $image) {
                if (file_exists($dir . $image['id_product'] . '-' . $image['id_image'] . '.jpg')) {
                    foreach ($result as $k => $module) {
                        if ($moduleInstance = Module::getInstanceByName($module['name']) and is_callable(array($moduleInstance, 'hookwatermark'))) {
                            call_user_func(array($moduleInstance, 'hookwatermark'), array('id_image' => $image['id_image'], 'id_product' => $image['id_product']));
                        }
                    }
                }
            }
        }
    }
 protected function generateImagesData()
 {
     $delimiter = ';';
     $line = array();
     $titles = array();
     $new_path = new Sampledatainstall();
     $f = fopen($new_path->sendPath() . 'output/images.vsc', 'w');
     foreach ($this->image_fields as $field => $array) {
         $titles[] = $array['label'];
     }
     fputcsv($f, $titles, $delimiter, '"');
     $images = Image::getAllImages();
     if ($images) {
         foreach ($images as $image) {
             $i = new Image($image['id_image'], $this->use_lang);
             foreach ($this->image_fields as $field => $array) {
                 $line[$field] = property_exists('Image', $field) && !is_array($i->{$field}) && !Tools::isEmpty($i->{$field}) ? $i->{$field} : '';
             }
             if (!$line[$field]) {
                 $line[$field] = '';
             }
             fputcsv($f, $line, $delimiter, '"');
         }
     }
     fclose($f);
 }
    protected function _regenerateWatermark($dir, $type = null)
    {
        $result = Db::getInstance()->executeS('
		SELECT m.`name` FROM `' . _DB_PREFIX_ . 'module` m
		LEFT JOIN `' . _DB_PREFIX_ . 'hook_module` hm ON hm.`id_module` = m.`id_module`
		LEFT JOIN `' . _DB_PREFIX_ . 'hook` h ON hm.`id_hook` = h.`id_hook`
		WHERE h.`name` = \'actionWatermark\' AND m.`active` = 1');
        if ($result && count($result)) {
            $productsImages = Image::getAllImages();
            foreach ($productsImages as $image) {
                $imageObj = new Image($image['id_image']);
                if (file_exists($dir . $imageObj->getExistingImgPath() . '.jpg')) {
                    foreach ($result as $module) {
                        $moduleInstance = Module::getInstanceByName($module['name']);
                        if ($moduleInstance && is_callable(array($moduleInstance, 'hookActionWatermark'))) {
                            call_user_func(array($moduleInstance, 'hookActionWatermark'), array('id_image' => $imageObj->id, 'id_product' => $imageObj->id_product, 'image_type' => $type));
                        }
                        if (time() - $this->start_time > $this->max_execution_time - 4) {
                            // stop 4 seconds before the tiemout, just enough time to process the end of the page on a slow server
                            return 'timeout';
                        }
                    }
                }
            }
        }
    }
예제 #9
0
 /**
  * Test grabbing all Images
  **/
 public function testGetAllValidImages()
 {
     //count the number of rows and save for later
     $numRows = $this->getConnection()->getRowCount("image");
     //Create new image and insert into database
     $image = new Image(null, $this->profile->getProfileId(), $this->VALID_IMAGETYPE, $this->VALID_IMAGEFILENAME, $this->VALID_IMAGETEXT, $this->VALID_IMAGEDATE);
     $image->insert($this->getPDO());
     //Grab data from database and ensure it matches our expectations
     $results = Image::getAllImages($this->getPDO());
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("image"));
     $this->assertContainsOnlyInstancesOf("Edu\\Cnm\\Jpegery\\Image", $results);
     //Grab the result from the array and validate it
     $pdoImage = $results[0];
     $this->assertEquals($pdoImage->getImageProfileId(), $this->profile->getProfileId());
     $this->assertEquals($pdoImage->getImageType(), $this->VALID_IMAGETYPE);
     $this->assertEquals($pdoImage->getImageFileName(), $this->VALID_IMAGEFILENAME);
     $this->assertEquals($pdoImage->getImageText(), $this->VALID_IMAGETEXT);
     $this->assertEquals($pdoImage->getImageDate(), $this->VALID_IMAGEDATE);
 }
예제 #10
0
<?php

error_reporting(0);
header('Content-Type:text/html;charset=utf8');
//接口
require 'include/DB.class.php';
require 'include/Image.class.php';
require 'include/Page.class.php';
$total = Image::total($_GET['sid']);
$typename = Image::getTypeName($_GET['sid']);
//分页
$page = new Page($total, 20);
$allImages = Image::getAllImages($_GET['sid'], $page->getLimit());
//需要传递一个参数,1-6表示有六个类,这个参数通过Get方式传递进来
?>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>图片情感标签标注系统-<?php 
echo $typename;
?>
</title> 

<link rel='stylesheet' href='style/style.css' media='screen' />
<link rel="stylesheet" type="text/css" href="style/basic.css">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/detail.js"></script>
<!--[if lt IE 9]>
예제 #11
0
    private function _regenerateWatermark($dir)
    {
        $result = Db::getInstance()->ExecuteS('
		SELECT m.`name` FROM `' . _DB_PREFIX_ . 'module` m
		LEFT JOIN `' . _DB_PREFIX_ . 'hook_module` hm ON hm.`id_module` = m.`id_module`
		LEFT JOIN `' . _DB_PREFIX_ . 'hook` h ON hm.`id_hook` = h.`id_hook`
		WHERE h.`name` = \'watermark\' AND m.`active` = 1');
        if ($result and sizeof($result)) {
            $productsImages = Image::getAllImages();
            foreach ($productsImages as $k => $image) {
                if (file_exists($dir . $image['id_product'] . '-' . $image['id_image'] . '.jpg')) {
                    foreach ($result as $k => $module) {
                        if ($moduleInstance = Module::getInstanceByName($module['name']) and is_callable(array($moduleInstance, 'hookwatermark'))) {
                            call_user_func(array($moduleInstance, 'hookwatermark'), array('id_image' => $image['id_image'], 'id_product' => $image['id_product']));
                        }
                        if (time() - $this->start_time > $this->max_execution_time - 4) {
                            // stop 4 seconds before the tiemout, just enough time to process the end of the page on a slow server
                            return 'timeout';
                        }
                    }
                }
            }
        }
    }
        private function regenerateProducts($imageType, $number)
        {
            $dir = constant($this->dirs['products']);
            $productsImages = Image::getAllImages();
            if (!array_key_exists($number - 1, $productsImages)) {
                return json_encode(array('error' => $this->l('Image unknowed') . ' ' . $number, 'max' => count($productsImages)));
            }
            $image = $productsImages[$number - 1];
            $imageObj = new Image($image['id_image']);
            $imageObj->id_product = $image['id_product'];
            if (file_exists($dir . $imageObj->getImgFolder() . DIRECTORY_SEPARATOR . $imageObj->id . '\\-' . stripslashes($imageType['name']) . '.jpg')) {
                unlink($dir . $imageObj->getImgFolder() . DIRECTORY_SEPARATOR . $imageObj->id . '\\-' . stripslashes($imageType['name']) . '.jpg');
            }
            if (file_exists($dir . $imageObj->getImgFolder() . DIRECTORY_SEPARATOR . $imageObj->id_product . '\\-' . $imageObj->id . '\\-' . stripslashes($imageType['name']) . '.jpg')) {
                unlink($dir . $imageObj->getImgFolder() . DIRECTORY_SEPARATOR . $imageObj->id_product . '\\-' . $imageObj->id . '\\-' . stripslashes($imageType['name']) . '.jpg');
            }
            if (file_exists($dir . DIRECTORY_SEPARATOR . $imageObj->id_product . '\\-' . $imageObj->id . '\\-' . stripslashes($imageType['name']) . '.jpg')) {
                unlink($dir . DIRECTORY_SEPARATOR . $imageObj->id_product . '\\-' . $imageObj->id . '\\-' . stripslashes($imageType['name']) . '.jpg');
            }
            if (file_exists($dir . $imageObj->getExistingImgPath() . '.jpg')) {
                if (!@getimagesize($dir . $imageObj->getExistingImgPath() . '.jpg')) {
                    return json_encode(array('error' => $this->l('Image invalid:') . ' ' . $dir . $imageObj->getExistingImgPath() . '.jpg', 'max' => count($productsImages)));
                }
                if (class_exists('ImageManager')) {
                    $result = ImageManager::resize($dir . $imageObj->getExistingImgPath() . '.jpg', $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg', (int) $imageType['width'], (int) $imageType['height']);
                } else {
                    $result = imageResize($dir . $imageObj->getExistingImgPath() . '.jpg', $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg', (int) $imageType['width'], (int) $imageType['height']);
                }
                if (!$result) {
                    return json_encode(array('error' => $this->l('Can\'t regenerate image') . ' ' . $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg ' . $this->l('from') . ' ' . $dir . $imageObj->getExistingImgPath() . '.jpg', 'max' => count($productsImages)));
                }
                $result = Db::getInstance()->ExecuteS('
					SELECT m.`name` FROM `' . _DB_PREFIX_ . 'module` m
					LEFT JOIN `' . _DB_PREFIX_ . 'hook_module` hm ON hm.`id_module` = m.`id_module`
					LEFT JOIN `' . _DB_PREFIX_ . 'hook` h ON hm.`id_hook` = h.`id_hook`
					WHERE (h.`name` = \'actionWatermark\' OR h.`name` = \'watermark\') AND m.`active` = 1');
                if ($result and sizeof($result)) {
                    foreach ($result as $k => $module) {
                        if ($moduleInstance = Module::getInstanceByName($module['name'])) {
                            if (is_callable(array($moduleInstance, 'hookActionWatermark'))) {
                                @call_user_func(array($moduleInstance, 'hookActionWatermark'), array('id_image' => $imageObj->id, 'id_product' => $imageObj->id_product));
                            } elseif (is_callable(array($moduleInstance, 'hookwatermark'))) {
                                @call_user_func(array($moduleInstance, 'hookwatermark'), array('id_image' => $imageObj->id, 'id_product' => $imageObj->id_product));
                            }
                        }
                    }
                }
            } else {
                return json_encode(array('error' => $this->l('Can\'t find image') . ' ' . $dir . $imageObj->getExistingImgPath() . '.jpg', 'max' => count($productsImages)));
            }
            return json_encode(array('error' => '', 'max' => count($productsImages)));
        }
예제 #13
0
파일: images.php 프로젝트: rodrisan/ps-cli
 public static function list_images()
 {
     $context = Context::getContext();
     $images = Image::getAllImages();
     $table = new Cli\Table();
     $table->setHeaders(array('id_image', 'id_product', 'product name', 'path'));
     foreach ($images as $image) {
         $product = new Product($image['id_product']);
         $img = new Image($image['id_image']);
         //print_r($img);
         //die();
         $table->addRow(array($image['id_image'], $image['id_product'], $product->name[$context->language->id], $img->getImgPath() . '.' . $img->image_format));
     }
     $table->display();
     return;
 }
    public function displayForm()
    {
        $images = Image::getAllImages();
        $r = '<div class="bootstrap">';
        $config = Configuration::get('image_regenerator_queue');
        $image_regenerator_queue_what = Configuration::get('image_regenerator_queue_what');
        $image_regenerator_queue_what = empty($image_regenerator_queue_what) ? "null" : '"' . $image_regenerator_queue_what . '"';
        if ($config) {
            $list = json_decode($config, true);
            if (!is_array($list) || count($list) == 0) {
                $list = false;
            }
        } else {
            $list = false;
        }
        if (!$list) {
            $list = array();
            $process = array(array('type' => 'categories', 'dir' => _PS_CAT_IMG_DIR_), array('type' => 'manufacturers', 'dir' => _PS_MANU_IMG_DIR_), array('type' => 'suppliers', 'dir' => _PS_SUPP_IMG_DIR_), array('type' => 'scenes', 'dir' => _PS_SCENE_IMG_DIR_), array('type' => 'products', 'dir' => _PS_PROD_IMG_DIR_), array('type' => 'stores', 'dir' => _PS_STORE_IMG_DIR_));
            foreach ($process as $proc) {
                $list[$proc["type"]] = array("todo" => array(), "done" => array(), "errors" => array());
                if ($proc["type"] == "products") {
                    foreach ($images as $img) {
                        $list["products"]["todo"][] = $img['id_image'];
                    }
                } else {
                    $scanned_directory = array_diff(scandir($proc['dir']), array('..', '.'));
                    foreach ($scanned_directory as $image) {
                        if (preg_match('/^[0-9]*\\.jpg$/', $image)) {
                            $list[$proc["type"]]["todo"][] = $image;
                        }
                    }
                }
            }
        }
        $textHIW = $this->l("You can regenerate all your images safely.");
        $r .= '
		<div class="panel">
			<h3>' . $this->l("Let's go") . '</h3>
			<p>' . $textHIW . '</p>
			<div class="clearfix"></div>
			<table width="100%" id="autoImg-buttons"></table>
			<div class="clearfix"></div>
			<div class="btn-toolbar" role="toolbar">
				<div class="btn-group">
					<button class="btn btn-primary" id="image_regenerator-pause"><span class="icon-pause"></span> ' . $this->l('PAUSE') . '</button>
					<button class="btn btn-success" id="image_regenerator-resume"><span class="icon-play"></span> ' . $this->l('RESUME') . '</button>
				</div>
				<div class="btn-group">
					<form method="post" id="image_regenerator_save_form">
						<input type="hidden" name="image_regenerator_queue_what" value=""/>
						<input type="hidden" name="image_regenerator_queue" value=""/>
					</form>
				</div>
				<div class="btn-group">
					<form method="post">
						<input type="hidden" name="image_regenerator_reinit" value="1"/>
						<button type="submit" class="btn btn-warning" id="image_regenerator-reinit">' . $this->l('RESET') . '</button>
					</form>
				</div>
				<div class="btn-group">
					<div class="checkbox">
						<label><input type="checkbox" value="1" id="image_regenerator-watermark"> ' . $this->l('Watermark ? (module watermark need to be enable)') . '</label>
					</div>
				</div>
			</div>
		</div>
		<div class="panel"><h3>' . $this->l('Debug') . '</h3><div id="autoImg-progress" style="width:100%;line-height:20px;height:60px;overflow:auto;"></div><br/><div class="clearfix"></div>
		<script>var image_regenerator_can_run_queue = true;var image_regenerator_queuing_what = ' . $image_regenerator_queue_what . ';
		var autoImg = $.parseJSON(\'' . json_encode($list) . '\');
		var autoImgPath = "' . $this->context->link->getAdminLink('AdminModules') . '&configure=' . $this->name . '";
		</script></div></div>';
        return $r;
    }