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


PHP Varien_Image::open方法代码示例

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


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

示例1: saveAction

 public function saveAction()
 {
     if ($this->getRequest()->getPost()) {
         try {
             $postData = $this->getRequest()->getPost();
             $imageModel = Mage::getModel('aitcg/mask');
             if (isset($_FILES['filename']['name']) and file_exists($_FILES['filename']['tmp_name'])) {
                 $uploader = new Varien_File_Uploader('filename');
                 $uploader->setAllowedExtensions(array('png'));
                 $uploader->setAllowRenameFiles(true);
                 $uploader->setFilesDispersion(false);
                 $path = $imageModel->getImagesPath();
                 $uploader->save($path, preg_replace('/[^A-Za-z\\d\\.]/', '_', $_FILES['filename']['name']));
                 $postData['filename'] = $uploader->getUploadedFileName();
             }
             $imageModel->load($this->getRequest()->getParam('imgid'))->setName($postData['name'])->setResize($postData['resize'])->setCategoryId($this->getRequest()->getParam('id'));
             if (isset($postData['filename'])) {
                 if ($imageModel->getFilename()) {
                     $fullPath = $imageModel->getImagesPath() . $imageModel->getFilename();
                     @unlink($fullPath);
                     $fullPath = $imageModel->getImagesPath() . 'preview' . DS . $imageModel->getFilename();
                     @unlink($fullPath);
                 }
                 $imageModel->setFilename($postData['filename']);
                 $thumb = new Varien_Image($imageModel->getImagesPath() . $imageModel->getFilename());
                 $thumb->open();
                 $thumb->keepAspectRatio(true);
                 $thumb->keepFrame(true);
                 $thumb->backgroundColor(array(255, 255, 255));
                 #$thumb->keepTransparency(true);
                 $thumb->resize(135);
                 $thumb->save($imageModel->getImagesPath() . 'preview' . DS . $imageModel->getFilename());
                 $imageModel->createInvertMask();
             }
             $imageModel->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully saved'));
             Mage::getSingleton('adminhtml/session')->setImageData(false);
             $this->_redirect('*/*/', array('id' => $this->getRequest()->getParam('id')));
             return;
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
             Mage::getSingleton('adminhtml/session')->setImageData($this->getRequest()->getPost());
             $this->_redirect('*/*/edit', array('imgid' => $this->getRequest()->getParam('imgid'), 'id' => $this->getRequest()->getParam('id')));
             return;
         }
     }
     $this->_redirect('*/*/', array('id' => $this->getRequest()->getParam('id')));
 }
开发者ID:Eximagen,项目名称:BulletMagento,代码行数:48,代码来源:ImageController.php

示例2: setFilenameWithUnlink

 public function setFilenameWithUnlink($filename)
 {
     if ($this->getFilename() && $this->getFilename() != $filename) {
         $fullPath = $this->getImagesPath() . $this->getFilename();
         @unlink($fullPath);
         $fullPath = $this->getImagesPath() . 'preview' . DS . $this->getFilename();
         @unlink($fullPath);
     }
     $this->setFilename($filename);
     $thumb = new Varien_Image($this->getImagesPath() . $this->getFilename());
     $thumb->open();
     $thumb->keepAspectRatio(true);
     $thumb->keepFrame(true);
     $thumb->backgroundColor(array(255, 255, 255));
     #$thumb->keepTransparency(true);
     $thumb->resize(135);
     $thumb->save($this->getImagesPath() . 'preview' . DS . $this->getFilename());
 }
开发者ID:Eximagen,项目名称:BulletMagento,代码行数:18,代码来源:Image.php

示例3: addWatermarkIfNeed

 public function addWatermarkIfNeed($imageLink)
 {
     if (!$this->isWatermarkEnabled()) {
         return $imageLink;
     }
     $imagePath = $this->imageLinkToPath($imageLink);
     if (!is_file($imagePath)) {
         return $imageLink;
     }
     $fileExtension = pathinfo($imagePath, PATHINFO_EXTENSION);
     $pathWithoutExtension = preg_replace('/\\.' . $fileExtension . '$/', '', $imagePath);
     $markingImagePath = $pathWithoutExtension . '-' . $this->getWatermarkHash() . '.' . $fileExtension;
     if (is_file($markingImagePath)) {
         $currentTime = Mage::helper('M2ePro')->getCurrentGmtDate(true);
         if (filemtime($markingImagePath) + self::WATERMARK_CACHE_TIME > $currentTime) {
             return $this->pathToImageLink($markingImagePath);
         }
         @unlink($markingImagePath);
     }
     $prevMarkingImagePath = $pathWithoutExtension . '-' . $this->getWatermarkPreviousHash() . '.' . $fileExtension;
     if (is_file($prevMarkingImagePath)) {
         @unlink($prevMarkingImagePath);
     }
     $varDir = new Ess_M2ePro_Model_General_VariablesDir(array('child_folder' => 'ebay/template/description/watermarks'));
     $watermarkPath = $varDir->getPath() . $this->getId() . '.png';
     if (!is_file($watermarkPath)) {
         $varDir->create();
         @file_put_contents($watermarkPath, $this->getWatermarkImage());
     }
     $watermarkPositions = array(self::WATERMARK_POSITION_TOP => Varien_Image_Adapter_Abstract::POSITION_TOP_RIGHT, self::WATERMARK_POSITION_MIDDLE => Varien_Image_Adapter_Abstract::POSITION_CENTER, self::WATERMARK_POSITION_BOTTOM => Varien_Image_Adapter_Abstract::POSITION_BOTTOM_RIGHT);
     $image = new Varien_Image($imagePath);
     $imageOriginalHeight = $image->getOriginalHeight();
     $imageOriginalWidth = $image->getOriginalWidth();
     $image->open();
     $image->setWatermarkPosition($watermarkPositions[$this->getWatermarkPosition()]);
     $watermark = new Varien_Image($watermarkPath);
     $watermarkOriginalHeight = $watermark->getOriginalHeight();
     $watermarkOriginalWidth = $watermark->getOriginalWidth();
     if ($this->isWatermarkScaleModeStretch()) {
         $image->setWatermarkPosition(Varien_Image_Adapter_Abstract::POSITION_STRETCH);
     }
     if ($this->isWatermarkScaleModeInWidth()) {
         $watermarkWidth = $imageOriginalWidth;
         $heightPercent = $watermarkOriginalWidth / $watermarkWidth;
         $watermarkHeight = (int) ($watermarkOriginalHeight / $heightPercent);
         $image->setWatermarkWidth($watermarkWidth);
         $image->setWatermarkHeigth($watermarkHeight);
     }
     if ($this->isWatermarkScaleModeNone()) {
         $image->setWatermarkWidth($watermarkOriginalWidth);
         $image->setWatermarkHeigth($watermarkOriginalHeight);
         if ($watermarkOriginalHeight > $imageOriginalHeight) {
             $image->setWatermarkHeigth($imageOriginalHeight);
             $widthPercent = $watermarkOriginalHeight / $imageOriginalHeight;
             $watermarkWidth = (int) ($watermarkOriginalWidth / $widthPercent);
             $image->setWatermarkWidth($watermarkWidth);
         }
         if ($watermarkOriginalWidth > $imageOriginalWidth) {
             $image->setWatermarkWidth($imageOriginalWidth);
             $heightPercent = $watermarkOriginalWidth / $imageOriginalWidth;
             $watermarkHeight = (int) ($watermarkOriginalHeight / $heightPercent);
             $image->setWatermarkHeigth($watermarkHeight);
         }
     }
     $opacity = 100;
     if ($this->isWatermarkTransparentEnabled()) {
         $opacity = 30;
     }
     $image->setWatermarkImageOpacity($opacity);
     $image->watermark($watermarkPath);
     $image->save($markingImagePath);
     return $this->pathToImageLink($markingImagePath);
 }
开发者ID:xiaoguizhidao,项目名称:bb,代码行数:73,代码来源:Description.php


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