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


PHP Varien_Image::setWatermarkWidth方法代码示例

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


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

示例1: run

 /**
  * Run script
  *
  */
 public function run()
 {
     if (!$this->getArg('d')) {
         echo $this->usageHelp();
         return;
     }
     /** @var $iterator SplFileObject[] */
     $iterator = new DirectoryIterator($this->getArg('d'));
     $start = microtime(true);
     $i = 0;
     $max = 0;
     do {
         foreach ($iterator as $file) {
             if (!$file->isDir()) {
                 $image = new Varien_Image($this->getArg('d') . DS . $file->getFilename(), Varien_Image_Adapter::ADAPTER_IM);
                 $image->keepFrame(true);
                 $image->keepAspectRatio(true);
                 $image->keepTransparency(true);
                 $image->backgroundColor(array(255, 255, 255));
                 $image->resize(186, 500);
                 $image->setWatermarkImageOpacity(30);
                 $image->setWatermarkPosition(Varien_Image_Adapter_Abstract::POSITION_TOP_LEFT);
                 $image->setWatermarkHeigth(100);
                 $image->setWatermarkWidth(100);
                 $image->quality(80);
                 $watermark = $this->getArg('d') . DS . 'watermark' . DS . 'watermark.png';
                 if (is_readable($watermark)) {
                     $image->watermark($watermark);
                 }
                 $image->save($this->getArg('d') . DS . 'result', $file->getFilename());
             }
         }
     } while ($i++ < $max);
     $endMem = memory_get_usage(true);
     $end = microtime(true);
     echo "Duration in seconds: " . ($end - $start) . PHP_EOL;
     echo "Memory usage in MB: " . $endMem / 1024 / 1024 . PHP_EOL;
 }
开发者ID:sergeykalenyuk,项目名称:Perfect_Watermarks,代码行数:42,代码来源:imagemagicktest.php

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