本文整理汇总了PHP中Varien_Image_Adapter::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Image_Adapter::factory方法的具体用法?PHP Varien_Image_Adapter::factory怎么用?PHP Varien_Image_Adapter::factory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Image_Adapter
的用法示例。
在下文中一共展示了Varien_Image_Adapter::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resizeFile
/**
* Create thumbnail for image and save it to thumbnails directory
*
* @param string $source Image path to be resized
* @param bool $keepRation Keep aspect ratio or not
* @return bool|string Resized filepath or false if errors were occurred
*/
public function resizeFile($source, $keepRatio = true)
{
if (!Mage::helper('uaudio_storage')->isEnabled()) {
return parent::resizeFile($source, $keepRatio);
}
if (!$this->_getStorageModel()->fileExists($source)) {
return false;
}
try {
$targetFile = str_replace('//', '/', $this->getThumbsPath($source)) . DS . pathinfo($source, PATHINFO_BASENAME);
if (!$this->_getStorageModel()->fileExists($targetFile)) {
$tmpName = $this->_getStorageModel()->copyFileToTmp($source);
$image = Varien_Image_Adapter::factory('GD2');
$image->open($tmpName);
$width = $this->getConfigData('resize_width');
$height = $this->getConfigData('resize_height');
$image->keepAspectRatio($keepRatio);
$image->resize($width, $height);
$image->save($tmpName);
$dest = $this->_getStorageModel()->moveFile($tmpName, $targetFile);
return $dest;
} else {
return $this->_getStorageModel()->getRelativeDestination($targetFile);
}
} catch (Exception $e) {
Mage::logException($e);
return false;
}
}
示例2: resizeImg
public function resizeImg($fileName, $width, $height = null)
{
//$fileName = 'slideshow\slides\\'.$fileName;
$folderURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
$imageURL = $folderURL . $fileName;
$basePath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . 'slideshow' . DS . 'slides' . DS . $fileName;
$newPath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . 'slideshow' . DS . 'slides' . DS . 'thumbs' . DS . $fileName;
//if width empty then return original size image's URL
if ($width != '') {
//if image has already resized then just return URL
if (file_exists($basePath) && is_file($basePath) && !file_exists($newPath)) {
$imageObj = Varien_Image_Adapter::factory('GD2');
$imageObj->constrainOnly(true);
$imageObj->keepAspectRatio(true);
$imageObj->keepFrame(true);
$imageObj->backgroundColor(array(255, 255, 255));
$imageObj->open($basePath);
$imageObj->resize($width, $height);
$imageObj->save($newPath);
}
$resizedURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'resized' . DS . $fileName;
} else {
$resizedURL = $imageURL;
}
return $resizedURL;
}
示例3: directiveAction
/**
* Template directives callback
*
* TODO: move this to some model
*/
public function directiveAction()
{
$directive = $this->getRequest()->getParam('___directive');
$directive = Mage::helper('core')->urlDecode($directive);
$url = Mage::getModel('cms/adminhtml_template_filter')->filter($directive);
try {
$image = Varien_Image_Adapter::factory('GD2');
$image->open($url);
$image->display();
} catch (Exception $e) {
$image = Varien_Image_Adapter::factory('GD2');
$image->open(Mage::getSingleton('cms/wysiwyg_config')->getSkinImagePlaceholderPath());
$image->display();
/*
$image = imagecreate(100, 100);
$bkgrColor = imagecolorallocate($image,10,10,10);
imagefill($image,0,0,$bkgrColor);
$textColor = imagecolorallocate($image,255,255,255);
imagestring($image, 4, 10, 10, 'Skin image', $textColor);
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
*/
}
}
示例4: _beforeSave
/**
* Checks if choosen image adapter available
*
* @throws Mage_Core_Exception if some of adapter dipendencies was not loaded
* @return Mage_Adminhtml_Model_System_Config_Backend_File
*/
protected function _beforeSave()
{
$value = $this->getValue();
$adapter = Varien_Image_Adapter::factory($value);
try {
$adapter->checkDependencies();
} catch (Exception $e) {
$message = Mage::helper('Mage_Core_Helper_Data')->__('The specified image adapter cannot be used because of some missed dependencies.');
throw new Mage_Core_Exception($message);
}
return $this;
}
示例5: directiveAction
/**
* Template directives callback
*
* TODO: move this to some model
*/
public function directiveAction()
{
$directive = $this->getRequest()->getParam('___directive');
$directive = Mage::helper('core')->urlDecode($directive);
$url = Mage::getModel('cms/adminhtml_template_filter')->filter($directive);
try {
$image = Varien_Image_Adapter::factory('GD2');
$image->open($url);
$image->display();
} catch (Exception $e) {
$image = Varien_Image_Adapter::factory('GD2');
$image->open(Mage::getSingleton('cms/wysiwyg_config')->getSkinImagePlaceholderPath());
$image->display();
}
}
示例6: directiveAction
public function directiveAction()
{
$directive = $this->getRequest()->getParam("___directive");
$directive = Mage::helper("core")->urlDecode($directive);
$url = Mage::getModel("core/email_template_filter")->filter($directive);
try {
$image = Varien_Image_Adapter::factory("GD2");
$image->open($url);
$image->display();
} catch (Exception $e) {
$image = Varien_Image_Adapter::factory("GD2");
$image->open(Mage::getSingleton("cms/wysiwyg_config")->getSkinImagePlaceholderUrl());
$image->display();
}
}
示例7: directiveAction
/**
* Template directives callback
*
* TODO: move this to some model
*/
public function directiveAction()
{
$directive = $this->getRequest()->getParam('___directive');
$directive = Mage::helper('Mage_Core_Helper_Data')->urlDecode($directive);
$url = Mage::getModel('Mage_Core_Model_Email_Template_Filter')->filter($directive);
$adapter = Mage::helper('Mage_Core_Helper_Data')->getImageAdapterType();
$image = Varien_Image_Adapter::factory($adapter);
$response = $this->getResponse();
try {
$image->open($url);
$response->setHeader('Content-Type', $image->getMimeType())->setBody($image->getImage());
} catch (Exception $e) {
$image->open(Mage::getSingleton('Mage_Cms_Model_Wysiwyg_Config')->getSkinImagePlaceholderUrl());
$response->setHeader('Content-Type', $image->getMimeType())->setBody($image->getImage());
Mage::logException($e);
}
}
示例8: directiveAction
public function directiveAction()
{
if (!Mage::helper('uaudio_storage')->isEnabled()) {
return parent::directiveAction();
}
$storageModel = Mage::getSingleton('core/file_storage')->getStorageModel();
$directive = $this->getRequest()->getParam('___directive');
$directive = Mage::helper('core')->urlDecode($directive);
$url = Mage::getModel('cms/adminhtml_template_filter')->filter($directive);
if ($storageModel->fileExists($url)) {
$url = ltrim(str_replace(Mage::getBaseDir('media'), '', $url), '/');
$this->getResponse()->setRedirect(Mage::getBaseUrl('media') . $url);
} else {
$image = Varien_Image_Adapter::factory('GD2');
$image->open(Mage::getSingleton('cms/wysiwyg_config')->getSkinImagePlaceholderPath());
$image->display();
}
}
示例9: _resizeImage
/**
* Resize image and create cached file with the new size.
*
* @param $source
* @param $width
* @param $height
* @param bool $keep_ration
* @return bool|string
*/
private function _resizeImage($source, $width, $height, $keep_ration = true)
{
$path_media = Mage::getBaseDir('media');
if (!is_file($path_media . $source) || !is_readable($path_media . $source)) {
return false;
}
$path_image = Mage::app()->getStore()->getConfig('slider/options/folder');
$path_cache = $path_media . $path_image . DS . 'cache' . DS . $width . 'x' . $height;
$this->checkFolderExists($path_cache);
$image = Varien_Image_Adapter::factory('GD2');
$image->open($path_media . $source);
$image->keepAspectRatio($keep_ration);
$image->resize($width, $height);
$_destination = $path_cache . DS . pathinfo($source, PATHINFO_BASENAME);
$image->save($_destination);
if (is_file($_destination)) {
return $_destination;
}
return false;
}
示例10: _getAdapter
/**
* Retrieve image adapter object
*
* @param string $adapter
* @return Varien_Image_Adapter_Abstract
*/
protected function _getAdapter($adapter = null)
{
if (!isset($this->_adapter)) {
$this->_adapter = Varien_Image_Adapter::factory($adapter);
}
return $this->_adapter;
}
示例11: thumbnailAction
/**
* Generate image thumbnail on the fly
*/
public function thumbnailAction()
{
$file = $this->getRequest()->getParam('file');
$file = Mage::helper('cms/wysiwyg_images')->idDecode($file);
$thumb = $this->getStorage()->resizeOnTheFly($file);
if ($thumb !== false) {
$image = Varien_Image_Adapter::factory('GD2');
$image->open($thumb);
$image->display();
} else {
// todo: genearte some placeholder
}
}
示例12: resizeFile
/**
* Create thumbnail for image and save it to thumbnails directory
*
* @param string $source Image path to be resized
* @param bool $keepRation Keep aspect ratio or not
* @return bool|string Resized filepath or false if errors were occurred
*/
public function resizeFile($source, $keepRation = true)
{
if (!is_file($source) || !is_readable($source)) {
return false;
}
$targetDir = $this->getThumbsPath($source);
$io = new Varien_Io_File();
if (!$io->isWriteable($targetDir)) {
$io->mkdir($targetDir);
}
if (!$io->isWriteable($targetDir)) {
return false;
}
$image = Varien_Image_Adapter::factory('GD2');
$image->open($source);
$width = $this->getConfigData('resize_width');
$height = $this->getConfigData('resize_height');
$image->keepAspectRatio($keepRation);
$image->resize($width, $height);
$dest = $targetDir . DS . pathinfo($source, PATHINFO_BASENAME);
$image->save($dest);
if (is_file($dest)) {
return $dest;
}
return false;
}
示例13: thumbnailAction
/**
* Generate image thumbnail on the fly
*/
public function thumbnailAction()
{
$file = $this->getRequest()->getParam('file');
$file = Mage::helper('Mage_Cms_Helper_Wysiwyg_Images')->idDecode($file);
$thumb = $this->getStorage()->resizeOnTheFly($file);
if ($thumb !== false) {
$adapter = Mage::helper('Mage_Core_Helper_Data')->getImageAdapterType();
$image = Varien_Image_Adapter::factory($adapter);
$image->open($thumb);
$this->getResponse()->setHeader('Content-Type', $image->getMimeType())->setBody($image->getImage());
} else {
// todo: genearte some placeholder
}
}
示例14: resizeFile
/**
* Create thumbnail for image and save it to thumbnails directory
*
* @param string $source Image path to be resized
* @param bool $keepRation Keep aspect ratio or not
* @return bool|string Resized filepath or false if errors were occurred
*/
public function resizeFile($source, $keepRation = true)
{
if (!$this->_filesystem->isFile($source) || !$this->_filesystem->isReadable($source)) {
return false;
}
$targetDir = $this->getThumbsPath($source);
if (!$this->_filesystem->isWritable($targetDir)) {
$this->_filesystem->createDirectory($targetDir);
}
if (!$this->_filesystem->isWritable($targetDir)) {
return false;
}
$adapter = Mage::helper('Mage_Core_Helper_Data')->getImageAdapterType();
$image = Varien_Image_Adapter::factory($adapter);
$image->open($source);
$width = $this->getConfigData('resize_width');
$height = $this->getConfigData('resize_height');
$image->keepAspectRatio($keepRation);
$image->resize($width, $height);
$dest = $targetDir . DS . pathinfo($source, PATHINFO_BASENAME);
$image->save($dest);
if ($this->_filesystem->isFile($dest)) {
return $dest;
}
return false;
}
示例15: getImageAdapter
/**
* @param $value
* @return Varien_Image_Adapter_Gd2|Varien_Image_Adapter_Imagemagic|Varien_Image_Adapter_ImagemagicExternal
*/
public function getImageAdapter($value)
{
return Varien_Image_Adapter::factory($value);
}