本文整理汇总了PHP中Varien_Image::backgroundColor方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Image::backgroundColor方法的具体用法?PHP Varien_Image::backgroundColor怎么用?PHP Varien_Image::backgroundColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Image
的用法示例。
在下文中一共展示了Varien_Image::backgroundColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _entityImageUrl
protected function _entityImageUrl(Varien_Object $entity, $width, $height, $entityField)
{
$entityPath = $entity->getData($entityField);
if (!$entityPath) {
return null;
}
$dstPath = array('cache', Mage::app()->getStore()->getId(), $entityField, $width . 'x' . $height, $entityPath);
$dstFile = $this->getBaseMediaPath() . DS . implode(DS, $dstPath);
if (!file_exists($dstFile)) {
$srcPath = array($entityPath);
$srcFile = $this->getBaseMediaPath() . DS . implode(DS, $srcPath);
if (!file_exists($srcFile)) {
return null;
}
$image = new Varien_Image($srcFile);
$image->keepAspectRatio(true);
$image->keepTransparency(true);
$image->keepFrame(true);
$image->constrainOnly(false);
$image->backgroundColor(array(255, 255, 255));
$image->resize($width, $height);
$image->save($dstFile);
}
return $this->getBaseMediaUrl() . '/' . implode('/', $dstPath);
}
示例2: getCatResizedImage
public function getCatResizedImage($cat, $width, $height = null, $quality = 100)
{
if (!$cat->getThumbnail()) {
return false;
}
$imageUrl = Mage::getBaseDir('media') . DS . "catalog" . DS . "category" . DS . $cat->getThumbnail();
if (!is_file($imageUrl)) {
return false;
}
$imageResized = Mage::getBaseDir('media') . DS . "catalog" . DS . "category" . DS . "cache" . DS . "cat_resized" . DS . $cat->getThumbnail();
// Because clean Image cache function works in this folder only
//if (! file_exists ( $imageResized ) && file_exists ( $imageUrl ) || file_exists($imageUrl) && filemtime($imageUrl) > filemtime($imageResized)) :
$imageObj = new Varien_Image($imageUrl);
$imageObj->constrainOnly(true);
$imageObj->keepAspectRatio(true);
$imageObj->keepFrame(true);
// ep
$imageObj->quality($quality);
$imageObj->keepTransparency(true);
// png
$imageObj->backgroundColor(array(255, 255, 255));
$imageObj->resize($width, $height);
$imageObj->save($imageResized);
//endif;
if (file_exists($imageResized)) {
return Mage::getBaseUrl('media') . "/catalog/category/cache/cat_resized/" . $cat->getThumbnail();
} else {
return $this->getImageUrl();
}
}
示例3: resize
public function resize($imageUrl, $width, $height)
{
if (!file_exists(Mage::getBaseDir('media') . DS . "catalog" . DS . "category" . DS . "resized")) {
mkdir(Mage::getBaseDir('media') . DS . "catalog" . DS . "category" . DS . "resized", 0777, true);
}
$imageName = substr(strrchr($imageUrl, "/"), 1);
if ('255,255,255' !== $this->getBackgroundColor(true)) {
$imageName = $width . 'x' . $height . '/' . $this->getBackgroundColor(true) . '/' . $imageName;
} else {
$imageName = $width . 'x' . $height . '/' . $imageName;
}
$imageResized = Mage::getBaseDir('media') . DS . "catalog" . DS . "category" . DS . "resized" . DS . $imageName;
$imagePath = str_replace(Mage::getBaseUrl('media'), 'media/', $imageUrl);
$imagePath = Mage::getBaseDir() . DS . str_replace("/", DS, $imagePath);
if (!file_exists($imageResized) && file_exists($imagePath)) {
$imageObj = new Varien_Image($imagePath);
$imageObj->constrainOnly(true);
$imageObj->keepAspectRatio(true);
$imageObj->keepFrame(true);
$imageObj->keepTransparency(true);
$imageObj->backgroundColor($this->getBackgroundColor());
$imageObj->resize($width, $height);
$imageObj->save($imageResized);
}
$imageUrl = Mage::getBaseUrl('media') . "catalog/category/resized/" . $imageName;
return $imageUrl;
}
示例4: getProfileImage
public function getProfileImage()
{
if (isset($this->_seller['sstech_profileimage']) && ($_file_name = $this->_seller['sstech_profileimage'])) {
$_media_dir = Mage::getBaseDir('media') . DS . 'customer' . DS;
// Here i create a resize folder. for upload new category image
$cache_dir = $_media_dir . 'resize' . DS;
if (file_exists($cache_dir . $_file_name)) {
$img = Mage::getBaseUrl('media') . 'customer' . DS . 'resize' . $_file_name;
} elseif (file_exists($_media_dir . $_file_name)) {
if (!is_dir($cache_dir)) {
mkdir($cache_dir);
}
$_image = new Varien_Image($_media_dir . $_file_name);
$_image->constrainOnly(false);
$_image->keepAspectRatio(true);
$_image->keepFrame(true);
$_image->keepTransparency(true);
$_image->backgroundColor(array(255, 255, 255));
$_image->resize(300, null);
// change image height, width
$_image->save($cache_dir . $_file_name);
$img = Mage::getBaseUrl('media') . 'customer' . DS . 'resize' . $_file_name;
}
}
if (!isset($img)) {
$img = Mage::getBaseUrl('media') . "default_user.jpg";
}
return $img;
}
示例5: resizeImg
public function resizeImg($fileName, $width, $height = '')
{
$folderURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
$imageURL = $folderURL . $fileName;
$basePath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . $fileName;
$newPath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . "resized" . 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 = new Varien_Image($basePath);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->keepFrame(TRUE);
$imageObj->backgroundColor(array(255, 255, 255));
// white background!
$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;
}
示例6: getResizedUrl
public function getResizedUrl($imgUrl, $x, $y = NULL)
{
$imgPath = $this->splitImageValue($imgUrl, "path");
$imgName = $this->splitImageValue($imgUrl, "name");
/**
* Path with Directory Seperator
*/
$imgPath = str_replace("/", DS, $imgPath);
/**
* Absolute full path of Image
*/
$imgPathFull = Mage::getBaseDir("media") . DS . $imgPath . DS . $imgName;
/**
* If Y is not set set it to as X
*/
$widht = $x;
$y ? $height = $y : ($height = $x);
/**
*
* Resize folder is widthXheight
*/
$resizeFolder = $widht . "X" . $height;
/**
* Image resized path will then be
*/
$imageResizedPath = Mage::getBaseDir("media") . DS . $imgPath . DS . $resizeFolder . DS . $imgName;
/**
* First check in cache i.e image resized path
* If not in cache then create image of the width=X and height = Y
*/
if (!file_exists($imageResizedPath) && file_exists($imgPathFull)) {
$imageObj = new Varien_Image($imgPathFull);
$imageObj->constrainOnly(true);
// image picture will not be bigger, than it was
$imageObj->keepAspectRatio(true);
// image picture width/height will not be distorted
$imageObj->keepFrame(true);
// image will have dimensions, set in $width/$height
$imageObj->keepTransparency(true);
$imageObj->backgroundColor(array(255, 255, 255));
$imageObj->resize($widht, $height);
$imageObj->save($imageResizedPath);
}
/**
* Else image is in cache replace the Image Path with / for http path.
*/
$imgUrl = str_replace(DS, "/", $imgPath);
/**
* Return full http path of the image
*/
return Mage::getBaseUrl("media") . $imgUrl . "/" . $resizeFolder . "/" . $imgName;
}
示例7: resize
/**
* if there's no thumb for the image, we make it
*
* @param string $imageName
* @param int $size
*
* @return string
*/
public function resize($imageName, $size)
{
$helper = Mage::helper('adjicon');
$fileName = $helper->getThumbnailFileName($size, $imageName);
if (!file_exists($this->_imagePath . $fileName)) {
$image = new Varien_Image($this->_imagePath . $imageName);
$image->keepFrame(true);
$image->keepAspectRatio(true);
$image->keepTransparency(true);
$image->backgroundColor(array(255, 255, 255));
$image->resize($size);
$image->save(null, $fileName);
}
return $fileName;
}
示例8: 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')));
}
示例9: 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());
}
示例10: _getResizedImage
protected function _getResizedImage($file, $width, $height, $resizeMode = 'cover')
{
if (empty($file)) {
return false;
}
$width = (int) $width;
$height = (int) $height;
$imagePath = $this->getImageFullPath($file);
$imageFileResized = $width . '_' . $height . '_' . $resizeMode . DS . $file;
$imageFileResizedFullPath = $this->getImageCacheFullPath($imageFileResized);
if (!file_exists($imageFileResizedFullPath) && file_exists($imagePath) || file_exists($imagePath) && filemtime($imagePath) > filemtime($imageFileResizedFullPath)) {
$finalAspectRatio = $width / $height;
$imageObj = new Varien_Image($imagePath);
$imageObj->backgroundColor(array(255, 255, 255));
$originalWidth = (int) $imageObj->getOriginalWidth();
$originalHeight = (int) $imageObj->getOriginalHeight();
$originalAspectRatio = $originalWidth / $originalHeight;
if ($resizeMode == 'cover') {
if ($originalAspectRatio > $finalAspectRatio) {
$cropWidth = $finalAspectRatio * $originalHeight;
$widthDiff = $originalWidth - $cropWidth;
$cropX = (int) ($widthDiff / 2);
$imageObj->crop(0, $cropX, $cropX, 0);
} else {
$cropHeight = (int) ($originalWidth / $finalAspectRatio);
$heightDiff = $originalHeight - $cropHeight;
$cropY = (int) ($heightDiff / 2);
$imageObj->crop($cropY, 0, 0, $cropY);
}
} else {
$imageObj->constrainOnly(false);
$imageObj->keepAspectRatio(true);
$imageObj->keepFrame(true);
}
$imageObj->resize($width, $height);
$imageObj->quality(100);
$imageObj->save($imageFileResizedFullPath);
}
$imageCacheUrl = $this->getImageCacheUrl($imageFileResized);
if (file_exists($imageFileResizedFullPath)) {
return $imageCacheUrl;
}
return false;
}
示例11: resize
public function resize($width = 100, $height = null)
{
$height = $height ? $height : $width;
$this->createCacheFolder($width, $height);
$orgFolder = $this->getOrgFolder();
$cacheSizeFolder = $this->getCacheSizeFolder($width, $height);
$imageFile = $this->_cat->getImage();
if (!file_exists($cacheSizeFolder . DS . $imageFile)) {
if (file_exists($orgFolder . DS . $imageFile)) {
$fileImg = new Varien_Image($orgFolder . DS . $imageFile);
$fileImg->keepAspectRatio(true);
$fileImg->keepFrame(true);
$fileImg->keepTransparency(true);
$fileImg->constrainOnly(false);
$fileImg->backgroundColor(array(255, 255, 255));
$fileImg->resize($width, $height);
$fileImg->save($cacheSizeFolder . DS . $imageFile, null);
}
}
return Mage::getBaseUrl('media') . 'catalog/category/cache/' . $this->_cat->getId() . '/' . $width . 'x' . $height . '/' . $imageFile;
}
示例12: resize
public function resize($imageUrl, $width, $height)
{
if (!file_exists(Mage::getBaseDir('media') . DS . "catalog" . DS . "category" . DS . "resized")) {
mkdir(Mage::getBaseDir('media') . DS . "catalog" . DS . "category" . DS . "resized", 0777);
}
$imageName = substr(strrchr($imageUrl, "/"), 1);
$imageName = $width . '_' . $height . '_' . $imageName;
$imageResized = Mage::getBaseDir('media') . DS . "catalog" . DS . "category" . DS . "resized" . DS . $imageName;
$dirImg = Mage::getBaseDir() . str_replace("/", DS, strstr($imageUrl, '/media'));
if (!file_exists($imageResized) && file_exists($dirImg)) {
$imageObj = new Varien_Image($dirImg);
$imageObj->constrainOnly(true);
$imageObj->keepAspectRatio(true);
$imageObj->keepFrame(true);
// $imageObj->keepTransparency(true);
$imageObj->backgroundColor($this->getBackgroundColor());
$imageObj->resize($width, $height);
$imageObj->save($imageResized);
}
$imageUrl = Mage::getBaseUrl('media') . "catalog/category/resized/" . $imageName;
return $imageUrl;
}
示例13: 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;
}
示例14: convertImage
function convertImage($OriginalUrl, $ResizedlUrl = null)
{
$width = $this->width;
$height = $this->height;
if (!is_file($OriginalUrl)) {
return false;
}
if (!$ResizedlUrl) {
$ResizedlUrl = $OriginalUrl;
}
$imageObj = new Varien_Image($OriginalUrl);
$imageObj->constrainOnly(true);
$imageObj->keepAspectRatio(true);
$imageObj->keepFrame(true);
// force Frame
$imageObj->quality($this->quality);
$imageObj->keepTransparency(true);
// keep Transparency with image png
$imageObj->backgroundColor(array(255, 255, 255));
$imageObj->resize($width, $height);
$imageObj->save($ResizedlUrl);
}
示例15: thumbImageObj
/**
* Generate thumb image
* @param $imageUrl
* @param $imageResized
* @return $this
*/
public function thumbImageObj($imageUrl, $imageResized)
{
$imageObj = new Varien_Image($imageUrl);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->keepFrame(FALSE);
$imageObj->keepTransparency(true);
$imageObj->backgroundColor(array(255, 255, 255));
$imageObj->resize(200, 200);
$imageObj->save($imageResized);
}