当前位置: 首页>>代码示例>>PHP>>正文


PHP Image::getPathForCreation方法代码示例

本文整理汇总了PHP中Image::getPathForCreation方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::getPathForCreation方法的具体用法?PHP Image::getPathForCreation怎么用?PHP Image::getPathForCreation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Image的用法示例。


在下文中一共展示了Image::getPathForCreation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: copyImage

 /**
  * Copy a product image
  *
  * @param integer $id_product Product Id for product image filename
  * @param integer $id_image Image Id for product image filename
  */
 public function copyImage($id_product, $id_image, $method = 'auto')
 {
     if (!isset($_FILES['image_product']['tmp_name'])) {
         return false;
     }
     if ($error = checkImage($_FILES['image_product'], $this->maxImageSize)) {
         $this->_errors[] = $error;
     } else {
         $image = new Image($id_image);
         if (!($new_path = $image->getPathForCreation())) {
             $this->_errors[] = Tools::displayError('An error occurred during new folder creation');
         }
         if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) or !move_uploaded_file($_FILES['image_product']['tmp_name'], $tmpName)) {
             $this->_errors[] = Tools::displayError('An error occurred during the image upload');
         } elseif (!imageResize($tmpName, $new_path . '.' . $image->image_format)) {
             $this->_errors[] = Tools::displayError('An error occurred while copying image.');
         } elseif ($method == 'auto') {
             $imagesTypes = ImageType::getImagesTypes('products');
             foreach ($imagesTypes as $k => $imageType) {
                 if (!imageResize($tmpName, $new_path . '-' . stripslashes($imageType['name']) . '.' . $image->image_format, $imageType['width'], $imageType['height'], $image->image_format)) {
                     $this->_errors[] = Tools::displayError('An error occurred while copying image:') . ' ' . stripslashes($imageType['name']);
                 }
             }
         }
         @unlink($tmpName);
         Module::hookExec('watermark', array('id_image' => $id_image, 'id_product' => $id_product));
     }
 }
开发者ID:nicolasjeol,项目名称:hec-ecommerce,代码行数:34,代码来源:AdminProducts.php

示例2: copyImg

 /**
  * copyImg copy an image located in $url and save it in a path
  * according to $entity->$id_entity .
  * $id_image is used if we need to add a watermark
  *
  * @param int $id_entity id of product or category (set in entity)
  * @param int $id_image (default null) id of the image if watermark enabled.
  * @param string $url path or url to use
  * @param string $entity 'products' or 'categories'
  * @param bool $regenerate
  * @return bool
  */
 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;
         case 'stores':
             $path = _PS_STORE_IMG_DIR_ . (int) $id_entity;
             break;
     }
     $url = urldecode(trim($url));
     $parced_url = parse_url($url);
     if (isset($parced_url['path'])) {
         $uri = ltrim($parced_url['path'], '/');
         $parts = explode('/', $uri);
         foreach ($parts as &$part) {
             $part = rawurlencode($part);
         }
         unset($part);
         $parced_url['path'] = '/' . implode('/', $parts);
     }
     if (isset($parced_url['query'])) {
         $query_parts = array();
         parse_str($parced_url['query'], $query_parts);
         $parced_url['query'] = http_build_query($query_parts);
     }
     if (!function_exists('http_build_url')) {
         require_once _PS_TOOL_DIR_ . 'http_build_url/http_build_url.php';
     }
     $url = http_build_url('', $parced_url);
     $orig_tmpfile = $tmpfile;
     if (Tools::copy($url, $tmpfile)) {
         // Evaluate the memory required to resize the image: if it's too much, you can't resize it.
         if (!ImageManager::checkImageMemoryLimit($tmpfile)) {
             @unlink($tmpfile);
             return false;
         }
         $tgt_width = $tgt_height = 0;
         $src_width = $src_height = 0;
         $error = 0;
         ImageManager::resize($tmpfile, $path . '.jpg', null, null, 'jpg', false, $error, $tgt_width, $tgt_height, 5, $src_width, $src_height);
         $images_types = ImageType::getImagesTypes($entity, true);
         if ($regenerate) {
             $previous_path = null;
             $path_infos = array();
             $path_infos[] = array($tgt_width, $tgt_height, $path . '.jpg');
             foreach ($images_types as $image_type) {
                 $tmpfile = self::get_best_path($image_type['width'], $image_type['height'], $path_infos);
                 if (ImageManager::resize($tmpfile, $path . '-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height'], 'jpg', false, $error, $tgt_width, $tgt_height, 5, $src_width, $src_height)) {
                     // the last image should not be added in the candidate list if it's bigger than the original image
                     if ($tgt_width <= $src_width && $tgt_height <= $src_height) {
                         $path_infos[] = array($tgt_width, $tgt_height, $path . '-' . stripslashes($image_type['name']) . '.jpg');
                     }
                     if ($entity == 'products') {
                         if (is_file(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $id_entity . '.jpg')) {
                             unlink(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $id_entity . '.jpg');
                         }
                         if (is_file(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $id_entity . '_' . (int) Context::getContext()->shop->id . '.jpg')) {
                             unlink(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $id_entity . '_' . (int) Context::getContext()->shop->id . '.jpg');
                         }
                     }
                 }
                 if (in_array($image_type['id_image_type'], $watermark_types)) {
                     Hook::exec('actionWatermark', array('id_image' => $id_image, 'id_product' => $id_entity));
                 }
             }
         }
     } else {
         @unlink($orig_tmpfile);
         return false;
     }
     unlink($orig_tmpfile);
     return true;
 }
开发者ID:M03G,项目名称:PrestaShop,代码行数:99,代码来源:AdminImportController.php

示例3: explode

 $image_url = explode('/', $prd['images']);
 $url = _PS_IMG_MGT_DIR_ . end($image_url);
 $product_has_images = (bool) Image::getImages($id_lang, $product->id);
 $image = new Image();
 $image->id_product = (int) $product->id;
 $image->position = Image::getHighestPosition($product->id) + 1;
 $image->cover = !$product_has_images ? true : false;
 $field_error = $image->validateFields(UNFRIENDLY_ERROR, true);
 $lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true);
 $id_shop_list = array();
 $errors = array();
 $warnings = array();
 $id_shop_list[] = $product->id_shop_default;
 if ($image->add()) {
     $image->associateTo($id_shop_list);
     $image->getPathForCreation();
     $image_final = $image->getPathForCreation() . '.jpg';
     if (Tools::copy($url, $image_final)) {
         $tgt_width = $tgt_height = 0;
         $src_width = $src_height = 0;
         $previous_path = null;
         $path_infos = array();
         $images_types = ImageType::getImagesTypes('products', true);
         foreach ($images_types as $image_type) {
             if (ImageManager::resize($image_final, $image->getPathForCreation() . '-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height'], 'jpg', false, $error, $tgt_width, $tgt_height, 5, $src_width, $src_height)) {
                 if (is_file(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $product->id . '.jpg')) {
                     unlink(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $product->id . '.jpg');
                 }
                 if (is_file(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $product->id . '_' . (int) Context::getContext()->shop->id . '.jpg')) {
                     unlink(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $product->id . '_' . (int) Context::getContext()->shop->id . '.jpg');
                 }
开发者ID:abdoumej,项目名称:libsamy,代码行数:31,代码来源:import.php

示例4: copyImg

 /**
  * copyImg copy an image located in $url and save it in a path
  * according to $entity->$id_entity .
  * $id_image is used if we need to add a watermark
  *
  * @param int $id_entity id of product or category (set in entity)
  * @param int $id_image (default null) id of the image if watermark enabled.
  * @param string $url path or url to use
  * @param string entity 'products' or 'categories'
  * @return void
  */
 private static function copyImg($id_entity, $id_image = NULL, $url, $entity = 'products')
 {
     $tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'ps_import');
     $watermark_types = explode(',', Configuration::get('WATERMARK_TYPES'));
     switch ($entity) {
         default:
         case 'products':
             $imageObj = new Image($id_image);
             $path = $imageObj->getPathForCreation();
             break;
         case 'categories':
             $path = _PS_CAT_IMG_DIR_ . (int) $id_entity;
             break;
     }
     $url_source_file = str_replace(' ', '%20', trim($url));
     if (@copy($url_source_file, $tmpfile)) {
         imageResize($tmpfile, $path . '.jpg');
         $imagesTypes = ImageType::getImagesTypes($entity);
         foreach ($imagesTypes as $k => $imageType) {
             imageResize($tmpfile, $path . '-' . stripslashes($imageType['name']) . '.jpg', $imageType['width'], $imageType['height']);
         }
         if (in_array($imageType['id_image_type'], $watermark_types)) {
             Module::hookExec('watermark', array('id_image' => $id_image, 'id_product' => $id_entity));
         }
     } else {
         unlink($tmpfile);
         return false;
     }
     unlink($tmpfile);
     return true;
 }
开发者ID:greench,项目名称:prestashop,代码行数:42,代码来源:AdminImport.php

示例5: loadImage

 public function loadImage($id_product, $images)
 {
     $images_array = $this->imagesToArray($images);
     $images_id = array();
     $product = new Product($id_product);
     $image_types = ImageType::getImagesTypes('product');
     if ($images_array) {
         foreach ($images_array as $img) {
             if (file_exists(_TM_ROOT_DIR_ . $img['url'])) {
                 //ajout de l'image au produit
                 $image = new Image();
                 $image->id_product = intval($product->id);
                 $image->position = Image::getHighestPosition($product->id) + 1;
                 if (!intval($product->id_image_default)) {
                     $image->cover = 1;
                 } else {
                     $image->cover = 0;
                 }
                 $image->legend = 0;
                 $image->add();
                 if ($image->cover) {
                     $product->id_image_default = (int) $image->id;
                 }
                 $id_image = $image->id;
                 $images_id[] = $id_image;
                 $path = $image->getPathForCreation();
                 //echo $imgDir.$img['url'];
                 @copy(_TM_ROOT_DIR_ . $img['url'], $path . '.jpg');
                 foreach ($image_types as $k => $image_type) {
                     ImageManager::resize(_TM_ROOT_DIR_ . $img['url'], $path . '-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
                 }
                 //@unlink($tmpName);
             } else {
                 $this->_output .= '<div class="alert error">Image not exists!</div>';
             }
             $product->update();
         }
     }
     return $images_id;
 }
开发者ID:yiuked,项目名称:tmcart,代码行数:40,代码来源:Import.php

示例6: copyImage

 public function copyImage($id_image, $type = 'product')
 {
     $image = new Image($id_image);
     if (!($new_path = $image->getPathForCreation())) {
         return array('error' => Tools::displayError('An error occurred during new folder creation'));
     }
     if (!($tmpName = tempnam(_TM_PRO_IMG_DIR, 'PS')) || !$this->upload($tmpName)) {
         return array('error' => Tools::displayError('An error occurred during the image upload'));
     } elseif (!ImageManager::resize($tmpName, $new_path . '.' . $image->image_format)) {
         return array('error' => Tools::displayError('An error occurred while copying image.'));
     } else {
         $imagesTypes = ImageType::getImagesTypes($type);
         foreach ($imagesTypes as $imageType) {
             if (!ImageManager::resize($tmpName, $new_path . '-' . stripslashes($imageType['name']) . '.' . $image->image_format, $imageType['width'], $imageType['height'], $image->image_format)) {
                 return array('error' => Tools::displayError('An error occurred while copying image:') . ' ' . stripslashes($imageType['name']));
             }
         }
     }
     unlink($tmpName);
     $img = array('id_image' => $image->id, 'name' => $this->getName());
     return array('success' => $img);
 }
开发者ID:yiuked,项目名称:tmcart,代码行数:22,代码来源:FileUploader.php

示例7: copyImg

 /**
  * From AdminImportController
  */
 protected static function copyImg($id_entity, $id_image = null, $url, $entity = 'products')
 {
     $tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'ps_import');
     $watermark_types = explode(',', Configuration::get('WATERMARK_TYPES'));
     switch ($entity) {
         case 'products':
             $image_obj = new Image($id_image);
             $path = $image_obj->getPathForCreation();
             break;
         case 'categories':
             $path = _PS_CAT_IMG_DIR_ . (int) $id_entity;
             break;
         default:
             break;
     }
     $url = str_replace(' ', '%20', trim($url));
     if (version_compare(_PS_VERSION_, '1.5', '<')) {
         include_once 'class/ImageManager.php';
         $imgSg = new ImageManagerCore();
         if (!$imgSg->checkImageMemoryLimit($url)) {
             return false;
         }
         if (@copy($url, $tmpfile)) {
             $imgSg->resize($tmpfile, $path . '.jpg');
             $images_types = ImageType::getImagesTypes($entity);
             foreach ($images_types as $image_type) {
                 $imgSg->resize($tmpfile, $path . '-' . Tools::stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
             }
         } elseif ($content = Tools::file_get_contents($url)) {
             $fp = fopen($tmpfile, "w");
             fwrite($fp, $content);
             fclose($fp);
             $imgSg->resize($tmpfile, $path . '.jpg');
             $images_types = ImageType::getImagesTypes($entity);
             foreach ($images_types as $image_type) {
                 $imgSg->resize($tmpfile, $path . '-' . Tools::stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
             }
         } else {
             unlink($tmpfile);
             return false;
         }
     } else {
         if (!ImageManager::checkImageMemoryLimit($url)) {
             return false;
         }
         if (@copy($url, $tmpfile)) {
             ImageManager::resize($tmpfile, $path . '.jpg');
             $images_types = ImageType::getImagesTypes($entity);
             foreach ($images_types as $image_type) {
                 ImageManager::resize($tmpfile, $path . '-' . Tools::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));
             }
         } elseif ($content = Tools::file_get_contents($url)) {
             $fp = fopen($tmpfile, "w");
             fwrite($fp, $content);
             fclose($fp);
             ImageManager::resize($tmpfile, $path . '.jpg');
             $images_types = ImageType::getImagesTypes($entity);
             foreach ($images_types as $image_type) {
                 ImageManager::resize($tmpfile, $path . '-' . Tools::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;
 }
开发者ID:ventsiwad,项目名称:presta_addons,代码行数:77,代码来源:importProduct.class.php

示例8: logResponse

             }
             $imgFile = IMAGE_IMPORT_FOLDER . $filepath;
             $fileExists = file_exists($imgFile);
             if (!$fileExists && !$productHasImage) {
                 logResponse('Image not found ' . $imgFile);
             } else {
                 $image = new Image();
                 $image->id_product = (int) $id;
                 $image->cover = (int) $cover;
                 $image->id = $imageId;
                 $image->id_image = $imageId;
                 $image->save();
                 $db->update('image_lang', array('legend' => addslashes($imageDesc)), "id_image = '" . $db->escape($image->id_image) . "'");
                 $imgFolder = Image::getImgFolderStatic($imageId);
                 if ($fileExists && !is_dir(_PS_IMG_DIR_ . 'p' . DIRECTORY_SEPARATOR . $imgFolder)) {
                     $new_path = $image->getPathForCreation();
                     if (file_exists($imgFile)) {
                         $imagesTypes = ImageType::getImagesTypes('products');
                         foreach ($imagesTypes as $imageType) {
                             if (!ImageManager::resize($imgFile, $new_path . '-' . stripslashes($imageType['name']) . '.' . $image->image_format, $imageType['width'], $imageType['height'], $image->image_format)) {
                                 logResponse('An error occurred while copying image:' . ' ' . stripslashes($imageType['name']));
                             }
                         }
                     }
                 }
             }
         }
     }
     logResponse("Product {$id} saved");
 }
 logResponse("Total {$j} products imported");
开发者ID:s-neilo,项目名称:prestashop-pohoda,代码行数:31,代码来源:stock.php

示例9: copyImg

 private function copyImg($item, $className)
 {
     require_once '../../images.inc.php';
     $identifier = $this->supportedImports[strtolower($className)]['identifier'];
     $matchId = $this->getMatchId(strtolower($className));
     $matchIdLang = $this->getMatchIdLang();
     switch ($className) {
         default:
         case 'Product':
             $path = _PS_PROD_IMG_DIR_;
             break;
         case 'Category':
             $path = _PS_CAT_IMG_DIR_;
             break;
         case 'Manufacturer':
             $path = _PS_MANU_IMG_DIR_;
             break;
         case 'Supplier':
             $path = _PS_SUPP_IMG_DIR_;
             break;
     }
     $cover = 1;
     if (array_key_exists($item[$identifier], $matchId)) {
         if (array_key_exists('images', $item) && !is_null($item['images'])) {
             foreach ($item['images'] as $key => $image) {
                 $tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'import');
                 if (@copy(str_replace(' ', '%20', $image), $tmpfile)) {
                     if ($className == 'Product') {
                         $image = new Image();
                         $image->id_product = (int) $matchId[$item[$identifier]];
                         $image->cover = $cover;
                         $image->position = Image::getHighestPosition((int) $matchId[$item[$identifier]]) + 1;
                         $legend = array();
                         foreach ($item['name'] as $key => $val) {
                             if (array_key_exists($key, $matchIdLang)) {
                                 $legend[$matchIdLang[$key]] = Tools::link_rewrite($val);
                             } else {
                                 $legend[Configuration::get('PS_LANG_DEFAULT')] = Tools::link_rewrite($val);
                             }
                         }
                         $image->legend = $legend;
                         $image->add();
                         $path = $image->getPathForCreation();
                         ImageManager::resize($tmpfile, $path . '.jpg');
                     } else {
                         ImageManager::resize($tmpfile, $path . (int) $matchId[$item[$identifier]] . '.jpg');
                     }
                 } else {
                     @unlink($tmpfile);
                 }
                 @unlink($tmpfile);
                 $cover = 0;
             }
         }
     }
 }
开发者ID:toufikadfab,项目名称:PrestaShop-1.5,代码行数:56,代码来源:shopimporter.php

示例10: copyImg

 private static function copyImg($id_entity, $id_image = null, $url, $entity = 'products')
 {
     $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;
     }
     $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 (@copy($url, $tmpfile)) {
         ImageManager::resize($tmpfile, $path . '.jpg');
         $images_types = ImageType::getImagesTypes($entity);
         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;
 }
开发者ID:blaz1988,项目名称:presta,代码行数:37,代码来源:uploadxml.php

示例11: copyImage

 /**
  * Copy a product image
  *
  * @param integer $id_product Product Id for product image filename
  * @param integer $id_image Image Id for product image filename
  */
 public function copyImage($id_product, $id_image, $method = 'auto')
 {
     if (!isset($_FILES['image_product']['tmp_name'])) {
         return false;
     }
     if ($error = ImageManager::validateUpload($_FILES['image_product'])) {
         $this->errors[] = $error;
     } else {
         $image = new Image($id_image);
         if (!($new_path = $image->getPathForCreation())) {
             $this->errors[] = Tools::displayError('An error occurred while attempting to create a new folder.');
         }
         if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image_product']['tmp_name'], $tmpName)) {
             $this->errors[] = Tools::displayError('An error occurred during the image upload process.');
         } elseif (!ImageManager::resize($tmpName, $new_path . '.' . $image->image_format)) {
             $this->errors[] = Tools::displayError('An error occurred while copying the image.');
         } elseif ($method == 'auto') {
             $imagesTypes = ImageType::getImagesTypes('products');
             foreach ($imagesTypes as $k => $image_type) {
                 if (!ImageManager::resize($tmpName, $new_path . '-' . stripslashes($image_type['name']) . '.' . $image->image_format, $image_type['width'], $image_type['height'], $image->image_format)) {
                     $this->errors[] = Tools::displayError('An error occurred while copying image:') . ' ' . stripslashes($image_type['name']);
                 }
             }
         }
         @unlink($tmpName);
         Hook::exec('actionWatermark', array('id_image' => $id_image, 'id_product' => $id_product));
     }
 }
开发者ID:rongandat,项目名称:vatfairfoot,代码行数:34,代码来源:AdminProductsController.php

示例12: copyImg15

function copyImg15($id_entity, $id_image = null, $url, $entity = 'products')
{
    $tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'ps_import');
    //fichier tempo vide
    $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;
    }
    $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;
    }
    //Echo("in routine url, before the copy");
    // 'file_exists' doesn't work on distant file, and getimagesize make the import slower.
    // Just hide the warning, the traitment will be the same.
    //echo(" - Copy image to:".$tmpfile." and then resize in :".$path);
    echo " register_globals: " . ini_get('register_globals');
    echo " safe_mode: " . ini_get('safe_mode');
    echo " allow_url_fopen: " . ini_get('allow_url_fopen');
    //if(isset($sourceFile))
    //{
    //$array_img = explode('/',$sourceFile);
    //}
    //if(copy($_POST['source'],"img/".end($array_img))){
    //echo(" - Copy ".$sourceFile." image to:"._PS_IMG_DIR_.end($array_img)." and then resize in :".$path);
    //if(copy($sourceFile,_PS_IMG_DIR_.end($array_img)))
    if ($version < 16000) {
        if (@copy($url, $tmpfile)) {
            ImageManager::resize($tmpfile, $path . '.jpg');
            //ImageManager::resize(_PS_IMG_DIR_.end($array_img), $path.'.jpg');
            $images_types = ImageType::getImagesTypes($entity);
            foreach ($images_types as $image_type) {
                ImageManager::resize($tmpfile, $path . '-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
            }
            //ImageManager::resize(_PS_IMG_DIR_.end($array_img), $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 {
            echo " - @copy failed, please check Apache parameters like safe_mode=off, register_globals=off, allows_url_fopen=true and writting right in /img/tmp and img/p folders";
            unlink($tmpfile);
            return false;
        }
    } else {
        if (Tools::copy($url, $tmpfile)) {
            ImageManager::resize($tmpfile, $path . '.jpg');
            //ImageManager::resize(_PS_IMG_DIR_.end($array_img), $path.'.jpg');
            $images_types = ImageType::getImagesTypes($entity);
            foreach ($images_types as $image_type) {
                ImageManager::resize($tmpfile, $path . '-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
            }
            //ImageManager::resize(_PS_IMG_DIR_.end($array_img), $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 {
            echo " - @copy failed, please check Apache parameters like safe_mode=off, register_globals=off, allows_url_fopen=true and writting right in /img/tmp and img/p folders";
            unlink($tmpfile);
            return false;
        }
    }
    unlink($tmpfile);
    return true;
}
开发者ID:EliosIT,项目名称:PS_AchatFilet,代码行数:72,代码来源:images_category_upload_resizing.php

示例13: copyImage

 public function copyImage($id_product, $id_image, $method = 'auto')
 {
     $image = new Image($id_image);
     if (!($new_path = $image->getPathForCreation())) {
         return array('error' => Tools::displayError('An error occurred during new folder creation'));
     }
     if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !$this->upload($tmpName)) {
         return array('error' => Tools::displayError('An error occurred during the image upload'));
     } elseif (!ImageManager::resize($tmpName, $new_path . '.' . $image->image_format)) {
         return array('error' => Tools::displayError('An error occurred while copying image.'));
     } elseif ($method == 'auto') {
         $imagesTypes = ImageType::getImagesTypes('products');
         foreach ($imagesTypes as $imageType) {
             /*
             	$theme = (Shop::isFeatureActive() ? '-'.$imageType['id_theme'] : '');
             	if (!ImageManager::resize($tmpName, $new_path.'-'.stripslashes($imageType['name']).$theme.'.'.$image->image_format, $imageType['width'], $imageType['height'], $image->image_format))
             		return array('error' => Tools::displayError('An error occurred while copying image:').' '.stripslashes($imageType['name']));
             */
             if (!ImageManager::resize($tmpName, $new_path . '-' . stripslashes($imageType['name']) . '.' . $image->image_format, $imageType['width'], $imageType['height'], $image->image_format)) {
                 return array('error' => Tools::displayError('An error occurred while copying image:') . ' ' . stripslashes($imageType['name']));
             }
         }
     }
     unlink($tmpName);
     Hook::exec('actionWatermark', array('id_image' => $id_image, 'id_product' => $id_product));
     if (!$image->update()) {
         return array('error' => Tools::displayError('Error while updating status'));
     }
     $img = array('id_image' => $image->id, 'position' => $image->position, 'cover' => $image->cover, 'name' => $this->getName(), 'legend' => $image->legend);
     return array('success' => $img);
 }
开发者ID:bravoman,项目名称:PrestaShop,代码行数:31,代码来源:FileUploader.php

示例14: copyImg

 /**
  * copyImg copy an image located in $url and save it in a path
  * according to $entity->$id_entity .
  * $id_image is used if we need to add a watermark
  *
  * @param int $id_entity id of product or category (set in entity)
  * @param int $id_image (default null) id of the image if watermark enabled.
  * @param string $url path or url to use
  * @param string entity 'products' or 'categories'
  * @return boolean
  */
 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));
     $url = urldecode($url);
     $parced_url = parse_url($url);
     if (isset($parced_url['path'])) {
         $uri = ltrim($parced_url['path'], '/');
         $parts = explode('/', $uri);
         foreach ($parts as &$part) {
             $part = urlencode($part);
         }
         unset($part);
         $parced_url['path'] = '/' . implode('/', $parts);
     }
     if (isset($parced_url['query'])) {
         $query_parts = array();
         parse_str($parced_url['query'], $query_parts);
         $parced_url['query'] = http_build_query($query_parts);
     }
     if (!function_exists('http_build_url')) {
         require_once _PS_TOOL_DIR_ . 'http_build_url/http_build_url.php';
     }
     $url = http_build_url('', $parced_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 makes the import slower.
     // Just hide the warning, the processing 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;
 }
开发者ID:ecssjapan,项目名称:guiding-you-afteropen,代码行数:76,代码来源:AdminImportController.php

示例15: copyImagesImage

 public function copyImagesImage($identifier)
 {
     $path = $this->img_path . 'p/';
     $image = new Image($this->retrieveId('image', $identifier));
     $dst_path = $image->getPathForCreation();
     if (!@copy($path . $identifier . '.jpg', $dst_path . '.' . $image->image_format)) {
         $this->setError($this->language->l('Cannot create image "%1$s" for entity "%2$s"', $identifier, 'product'));
         return;
     }
     @chmod($dst_path . '.' . $image->image_format, 0644);
     $types = ImageType::getImagesTypes('products');
     foreach ($types as $type) {
         $origin_file = $path . $identifier . '-' . $type['name'] . '.jpg';
         $target_file = $dst_path . '-' . $type['name'] . '.' . $image->image_format;
         // Test if dest folder is writable
         if (!is_writable(dirname($target_file))) {
             $this->setError($this->language->l('Cannot create image "%1$s" (bad permissions on folder "%2$s")', $identifier . '-' . $type['name'], dirname($target_file)));
         } elseif (file_exists($origin_file)) {
             if (!@copy($origin_file, $target_file)) {
                 $this->setError($this->language->l('Cannot create image "%1$s" for entity "%2$s"', $identifier . '-' . $type['name'], 'product'));
             }
             @chmod($target_file, 0644);
         } elseif (!ImageManager::resize($path . $identifier . '.jpg', $target_file, $type['width'], $type['height'])) {
             $this->setError($this->language->l('Cannot create image "%1$s" for entity "%2$s"', $identifier . '-' . $type['name'], 'product'));
         }
     }
 }
开发者ID:prestanesia,项目名称:PrestaShop,代码行数:27,代码来源:xmlLoader.php


注:本文中的Image::getPathForCreation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。