本文整理匯總了PHP中Varien_Image::getOriginalHeight方法的典型用法代碼示例。如果您正苦於以下問題:PHP Varien_Image::getOriginalHeight方法的具體用法?PHP Varien_Image::getOriginalHeight怎麽用?PHP Varien_Image::getOriginalHeight使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Varien_Image
的用法示例。
在下文中一共展示了Varien_Image::getOriginalHeight方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: createPreview
public function createPreview($name, $pathModule, $id, $width, $height)
{
if (isset($_FILES[$name]['name']) && $_FILES[$name]['name'] != null) {
$path = Mage::getBaseDir('media') . DS . $pathModule . DS;
$imageObj = new Varien_Image($path . '/' . $_FILES[$name]['name']);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(FALSE);
$imageObj->keepFrame(FALSE);
$currentRatio = $imageObj->getOriginalWidth() / $imageObj->getOriginalHeight();
$targetRatio = $width / $height;
if ($targetRatio > $currentRatio) {
$imageObj->resize($width, null);
} else {
$imageObj->resize(null, $height);
}
$diffWidth = $imageObj->getOriginalWidth() - $width;
$diffHeight = $imageObj->getOriginalHeight() - $height;
//$imageObj->resize($width, $height);
$imageObj->crop(floor($diffHeight * 0.5), floor($diffWidth / 2), ceil($diffWidth / 2), ceil($diffHeight * 0.5));
if (empty($id)) {
$id = Mage::getModel('evoqueflex/evoqueflex')->getCollection()->addOrder('slide_id', 'ASC')->getLastItem()->toArray();
$id = $id['slide_id'];
}
$userfile_extn = explode(".", strtolower($_FILES[$name]['name']));
$imageObj->save($path . 'preview_' . $id . '.' . $userfile_extn[1]);
}
}
示例2: getShortImageSize
public function getShortImageSize($item)
{
$width_max = Mage::getStoreConfig('clnews/news/shortdescr_image_max_width');
$height_max = Mage::getStoreConfig('clnews/news/shortdescr_image_max_height');
if (Mage::getStoreConfig('clnews/news/resize_to_max') == 1) {
$width = $width_max;
$height = $height_max;
} else {
$imageObj = new Varien_Image(Mage::getBaseDir('media') . DS . $item->getImageShortContent());
$original_width = $imageObj->getOriginalWidth();
$original_height = $imageObj->getOriginalHeight();
if ($original_width > $width_max) {
$width = $width_max;
} else {
$width = $original_width;
}
if ($original_height > $height_max) {
$height = $height_max;
} else {
$height = $original_height;
}
}
if ($item->getShortWidthResize()) {
$width = $item->getShortWidthResize();
} else {
$width;
}
if ($item->getShortHeightResize()) {
$height = $item->getShortHeightResize();
} else {
$height;
}
return array('width' => $width, 'height' => $height);
}
示例3: postAction
public function postAction()
{
if (!empty($_FILES)) {
$type = 'file';
if (isset($_FILES[$type]['name']) && $_FILES[$type]['name'] != '') {
try {
$uploadsDir = Mage::getBaseDir('upload');
$uploader = new Varien_File_Uploader($type);
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$path = Mage::getBaseDir('media') . DS . 'upload';
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
$uploader->save($path, $_FILES[$type]['name']);
$filename = $uploader->getUploadedFileName();
$md5 = md5($filename);
$owner = Mage::getSingleton('customer/session')->getCustomerId() ? Mage::getSingleton('customer/session')->getCustomerId() : Mage::getSingleton('customer/session')->getSessionId();
Mage::getModel('xxx_catalog/upload')->setMd5($md5)->setFilename($filename)->setOwner($owner)->save();
$varienImage = new Varien_Image($uploadsDir . $filename);
$width = $varienImage->getOriginalWidth();
$height = $varienImage->getOriginalHeight();
$data = ['id' => $md5, 'width' => $width, 'height' => $height];
echo json_encode($data);
die;
} catch (Exception $e) {
Mage::log($e->getMessage(), null, $this->_logFile);
echo json_encode(['error' => $this->__($e->getMessage())]);
}
}
}
$this->getResponse()->setRedirect(Mage::getUrl('*/*/index'));
}
示例4: getPopupActive
public function getPopupActive()
{
$preview = $this->getRequest()->getParam('popup');
$popupID = $this->getRequest()->getParam('popupid');
if ($preview == "preview" && !empty($popupID)) {
$arrPopup = Mage::getModel('popup/popup')->getPopupPreview($popupID);
} else {
$arrPopup = Mage::getModel('popup/popup')->getPopupActive();
}
if (!empty($arrPopup)) {
// If there is a link, process template tag
if (!empty($arrPopup["popup_url"])) {
$helper = Mage::helper('cms');
$processor = $helper->getPageTemplateProcessor();
$arrPopup["popup_url"] = $processor->filter($arrPopup["popup_url"]);
}
// If there is a content, process template tag
if (!empty($arrPopup["popup_content_html"])) {
$helper = Mage::helper('cms');
$processor = $helper->getPageTemplateProcessor();
$arrPopup["popup_content_html"] = $processor->filter($arrPopup["popup_content_html"]);
}
$popupID = $arrPopup["popup_id"];
$storeID = Mage::app()->getStore()->getId();
//Check Cookie
$cookiePopup = Mage::getSingleton('core/cookie')->get('cookie_popup_' . $storeID);
// If there's any cookie or new promo or preview mode
if (!$cookiePopup || $cookiePopup != $popupID || $this->getRequest()->getParam('popup') == 'preview') {
if (!$this->getRequest()->getParam('popup')) {
Mage::getSingleton('core/cookie')->set('cookie_popup_' . $storeID, $popupID, 3600 * 24 * 7);
}
if (!empty($arrPopup["popup_image"])) {
$pathImage = Mage::getBaseDir('media') . "/popup/" . $arrPopup["popup_image"];
if (file_exists($pathImage)) {
$imageObj = new Varien_Image($pathImage);
$arrPopup['popup_image_width'] = $imageObj->getOriginalWidth();
$arrPopup['popup_image_height'] = $imageObj->getOriginalHeight();
}
}
return $arrPopup;
}
} else {
return false;
}
}
示例5: _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;
}
示例6: getImageSize
public function getImageSize($image = null, $_maxW = 125, $_maxH = 125, $fix = false)
{
$_baseSrc = Mage::getSingleton('igallery/config')->getBaseMediaPath();
if (file_exists($_baseSrc . $image->getFile())) {
$_imageObject = new Varien_Image($_baseSrc . $image->getFile());
$_sizeArray = array($_imageObject->getOriginalWidth(), $_imageObject->getOriginalHeight());
$_defaultW = $_maxW;
$_defaultH = $_maxH;
if ($_sizeArray[0] / $_sizeArray[1] > $_defaultW / $_defaultH) {
$_defaultW *= floatval($_sizeArray[0] / $_sizeArray[1]) / floatval($_defaultW / $_defaultH);
} else {
$_defaultH *= floatval($_defaultW / $_defaultH) / floatval($_sizeArray[0] / $_sizeArray[1]);
}
if ($fix == 'width') {
if ($_defaultW > $_maxW) {
$_defaultH *= $_maxW / $_defaultW;
$_defaultW = $_maxW;
}
} elseif ($fix == 'height') {
if ($_defaultH > $_maxH) {
$_defaultW *= $_maxH / $_defaultH;
$_defaultH = $_maxH;
}
} else {
if ($_defaultW > $_maxW) {
$_defaultH *= $_maxW / $_defaultW;
$_defaultW = $_maxW;
} elseif ($_defaultH > $_maxH) {
$_defaultW *= $_maxH / $_defaultH;
$_defaultH = $_maxH;
}
}
return new Varien_Object(array('width' => round($_defaultW), 'height' => round($_defaultH)));
}
return false;
}
示例7: getImageSize
public function getImageSize($image = null, $w, $h, $fix = false)
{
if (file_exists($image->getPath())) {
try {
$i = new Varien_Image($image->getPath());
$s = array($i->getOriginalWidth(), $i->getOriginalHeight());
$_defaultW = $w;
$_defaultH = $h;
if ($s[0] / $s[1] > $_defaultW / $_defaultH) {
$_defaultW *= floatval($s[0] / $s[1]) / floatval($_defaultW / $_defaultH);
} else {
$_defaultH *= floatval($_defaultW / $_defaultH) / floatval($s[0] / $s[1]);
}
if ($fix == 'width') {
if ($_defaultW > $w) {
$_defaultH *= $w / $_defaultW;
$_defaultW = $w;
}
} elseif ($fix == 'height') {
if ($_defaultH > $h) {
$_defaultW *= $h / $_defaultH;
$_defaultH = $h;
}
} else {
if ($_defaultW > $w) {
$_defaultH *= $w / $_defaultW;
$_defaultW = $w;
} elseif ($_defaultH > $h) {
$_defaultW *= $h / $_defaultH;
$_defaultH = $h;
}
}
return new Varien_Object(array('width' => round($_defaultW), 'height' => round($_defaultH)));
} catch (Exception $e) {
}
}
return new Varien_Object(array('width' => round($w), 'height' => round($h)));
}
示例8: handleUpload
/**
* Returns array('success'=>true) or array('error'=>'error message')
*/
function handleUpload($uploadDirectory, $slider_dimensions, $replaceOldFile = FALSE)
{
if (!is_writable($uploadDirectory)) {
return array('error' => Mage::helper('lookbookslider')->__("File can't be uploaded. Upload directory isn't writable."));
}
if (!$this->filemodel) {
return array('error' => Mage::helper('lookbookslider')->__("Uploader error. File was not uploaded."));
}
$size = $this->filemodel->getSize();
if ($size == 0) {
return array('error' => Mage::helper('lookbookslider')->__("File is empty"));
}
if ($size > $this->sizeLimit) {
return array('error' => Mage::helper('lookbookslider')->__("File is too large"));
}
$pathinfo = pathinfo($this->filemodel->getName());
$filename = $pathinfo['filename'];
//$filename = md5(uniqid());
$filename = uniqid();
$ext = $pathinfo['extension'];
if ($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)) {
$these = implode(', ', $this->allowedExtensions);
return array('error' => Mage::helper('lookbookslider')->__("File can't be uploaded. It has an invalid extension, it should be one of %s.", $these));
}
if (!$replaceOldFile) {
/// don't overwrite previous files that were uploaded
while (file_exists($uploadDirectory . $filename . '.' . $ext)) {
$filename .= rand(10, 99);
}
}
if ($this->filemodel->save($uploadDirectory . $filename . '.' . $ext)) {
$imgPathFull = $uploadDirectory . $filename . '.' . $ext;
$image_dimensions = Mage::helper('lookbookslider')->getImageDimensions($imgPathFull);
if (!isset($image_dimensions['error'])) {
/////////////////////////////////////////////
$resized_image = new Varien_Image($imgPathFull);
$resized_image->constrainOnly(FALSE);
$resized_image->keepAspectRatio(TRUE);
$resized_image->keepTransparency(TRUE);
$resized_image->keepFrame(FALSE);
if ($slider_dimensions['width'] / $slider_dimensions['height'] > $resized_image->getOriginalWidth() / $resized_image->getOriginalHeight()) {
$resized_image->resize($slider_dimensions['width'], null);
} else {
$resized_image->resize(null, $slider_dimensions['height']);
}
$cropX = 0;
$cropY = 0;
if ($resized_image->getOriginalWidth() > $slider_dimensions['width']) {
$cropX = intval(($resized_image->getOriginalWidth() - $slider_dimensions['width']) / 2);
} elseif ($resized_image->getOriginalHeight() > $slider_dimensions['height']) {
$cropY = intval(($resized_image->getOriginalHeight() - $slider_dimensions['height']) / 2);
}
$resized_image->crop($cropY, $cropX, $cropX, $cropY);
$resized_image->save($imgPathFull);
$image_dimensions = Mage::helper('lookbookslider')->getImageDimensions($imgPathFull);
/////////////////////////////////////////////
} else {
return array('error' => Mage::helper('lookbookslider')->__("Could not get uploaded image dimensions."));
}
return array('success' => true, 'filename' => $filename . '.' . $ext, 'dimensions' => $image_dimensions);
} else {
return array('error' => Mage::helper('lookbookslider')->__("Could not save uploaded file. The upload was cancelled, or server error encountered"));
}
}
示例9: getCustomSizeImageUrl
/**
* Retrieve custom size image url
*
*
* @param string $imageUrl
* @param int $width
* @param int $height
* @return string|null
*/
public function getCustomSizeImageUrl($imageUrl, $width = 100, $height = 100)
{
$screenSize = $width . 'x' . $height;
$customDir = $this->getMediaPath('custom' . DS . $screenSize);
$this->_verifyDirExist($customDir);
$imageUrl = explode('/', $imageUrl);
$file = array_pop($imageUrl);
$filePath = Mage_XmlConnect_Model_Images::getBasePath() . DS . $file;
if (!file_exists($customDir . DS . $file)) {
$image = new Varien_Image($filePath);
$widthOriginal = $image->getOriginalWidth();
$heightOriginal = $image->getOriginalHeight();
if ($width != $widthOriginal) {
$widthOriginal = $width;
}
if ($height != $heightOriginal) {
$heightOriginal = $height;
}
if ($widthOriginal != $image->getOriginalWidth() || $heightOriginal != $image->getOriginalHeight()) {
$image->keepTransparency(true);
$image->keepFrame(true);
$image->keepAspectRatio(true);
$image->backgroundColor(array(255, 255, 255));
$image->resize($widthOriginal, $heightOriginal);
$image->save($customDir, basename($file));
}
}
return $this->getMediaUrl("custom/{$screenSize}/" . basename($file));
}
示例10: getCustomSizeImageUrl
/**
* Retrieve custom size image url
*
* @param string $imageFile
* @param int $width
* @param int $height
* @return string|bool
*/
public function getCustomSizeImageUrl($imageFile, $width = 100, $height = 100)
{
/** @var $imageHelper Mage_XmlConnect_Helper_Image */
$imageHelper = Mage::helper('xmlconnect/image');
$screenSize = $width . 'x' . $height;
$customDir = $imageHelper->getMediaPath('custom' . DS . $screenSize);
$ioFile = new Varien_Io_File();
$ioFile->checkAndCreateFolder($customDir);
$filePath = self::getBasePath() . DS . $imageFile;
$isImagePng = true;
if (!$ioFile->fileExists($filePath)) {
return false;
}
$originalImageType = $this->_getImageType($filePath);
if ($originalImageType !== IMAGETYPE_PNG) {
$imageFile = $this->_convertFileExtensionToPng($imageFile);
$isImagePng = false;
}
$customSizeFile = $customDir . DS . $imageFile;
if (!file_exists($customSizeFile)) {
if (!$isImagePng) {
$filePath = $this->_forcedConvertPng($filePath, $customSizeFile, $originalImageType);
}
$image = new Varien_Image($filePath);
$widthOriginal = $image->getOriginalWidth();
$heightOriginal = $image->getOriginalHeight();
if ($width != $widthOriginal) {
$widthOriginal = $width;
}
if ($height != $heightOriginal) {
$heightOriginal = $height;
}
if ($widthOriginal != $image->getOriginalWidth() || $heightOriginal != $image->getOriginalHeight()) {
$image->keepTransparency(true);
$image->keepFrame(true);
$image->keepAspectRatio(true);
$image->backgroundColor(array(0, 0, 0));
$image->resize($widthOriginal, $heightOriginal);
$image->save($customDir, basename($imageFile));
} else {
$ioFile->cp($filePath, $customSizeFile);
}
}
return $imageHelper->getMediaUrl("custom/{$screenSize}/" . basename($imageFile));
}
示例11: getCustomSizeImageUrl
/**
* Retrieve thumbnail image url
*
* @param string $imageUrl
* @param int $width
* @param int $height
* @return string|null
*/
public function getCustomSizeImageUrl($imageUrl, $width = 100, $height = 100)
{
$screenSize = $width . 'x' . $height;
$customDir = $this->getMediaPath('custom' . DS . $screenSize);
$this->_verifyDirExist($customDir);
$imageUrl = explode('/', $imageUrl);
$file = $imageUrl[count($imageUrl) - 1];
$filePath = $this->getDefaultSizeUploadDir() . DS . $file;
if (!file_exists($customDir . DS . $file)) {
$adapter = Mage::helper('Mage_Core_Helper_Data')->getImageAdapterType();
$image = new Varien_Image($filePath, $adapter);
$widthOriginal = $image->getOriginalWidth();
$heightOriginal = $image->getOriginalHeight();
if ($width != $widthOriginal) {
$widthOriginal = $width;
}
if ($height != $heightOriginal) {
$heightOriginal = $height;
}
if ($widthOriginal != $image->getOriginalWidth() || $heightOriginal != $image->getOriginalHeight()) {
$image->keepTransparency(true);
$image->keepFrame(true);
$image->keepAspectRatio(true);
$image->backgroundColor(array(255, 255, 255));
$image->resize($widthOriginal, $heightOriginal);
$image->save($customDir, basename($file));
}
}
return $this->getMediaUrl("custom/{$screenSize}/" . basename($file));
}
示例12: getThumbnail
public function getThumbnail($field_id, $filename, $width, $height = null)
{
$filename = Varien_File_Uploader::getCorrectFileName($filename);
$imageUrl = $this->getFileFullPath($field_id, $filename);
$file_info = @getimagesize($imageUrl);
if (!$file_info) {
return false;
}
if (strstr($file_info["mime"], "bmp")) {
return false;
}
if (file_exists($imageUrl)) {
$imageObj = new Varien_Image($imageUrl);
}
if (!$height && (double) substr(Mage::getVersion(), 0, 3) > 1) {
$height = round($imageObj->getOriginalHeight() * ($width / $imageObj->getOriginalWidth()));
}
$imageResized = $this->getFilePath($field_id) . "thumb" . DS . $width . 'x' . $height . '_' . $filename;
if (!file_exists($imageResized) && file_exists($imageUrl) || Mage::getStoreConfig('webforms/images/cache') == 0) {
if ((double) substr(Mage::getVersion(), 0, 3) > 1) {
$imageObj->keepAspectRatio(true);
$imageObj->keepTransparency(true);
}
$imageObj->resize($width, $height);
$imageObj->save($imageResized);
}
$url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . "webforms/" . $this->getId() . "/" . $field_id;
if ($this->getData('key_' . $field_id)) {
$url .= "/" . $this->getData('key_' . $field_id);
}
$url .= "/thumb/" . $width . 'x' . $height . '_' . urlencode($filename);
return $url;
}
示例13: resizeThumbnail1
public function resizeThumbnail1($thumbImage, $pathName, $width, $height)
{
$imagePathInput = Mage::getBaseDir('media') . DS . $pathName . DS . $thumbImage;
$imageName = $thumbImage;
if ($imageName == '') {
$imageName = 'no-image.png';
$imagePathInput = Mage::getBaseDir('media') . DS . 'brands' . DS . 'no-image.png';
}
$imagePathOutput = $pathName . DS . $width . 'x' . $height . DS . $imageName;
$imageUrl = str_replace(DS, '/', $imagePathOutput);
$imageUrl = Mage::getBaseUrl('media') . $imageUrl;
$pathBaseDir = Mage::getBaseDir('media') . DS . $imagePathOutput;
$this->setPlaceholder($imageUrl);
if (!is_file($pathBaseDir)) {
$_backgroundColor = array(255, 255, 255);
try {
$imageObj = new Varien_Image($imagePathInput);
$imageObj->backgroundColor($_backgroundColor);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->keepFrame(TRUE);
$h = $imageObj->getOriginalHeight();
$w = $imageObj->getOriginalWidth();
if ((double) $w / $h <= (double) $width / $height) {
$height = $height;
$width = $w / $h * $height;
$imageObj->resize($width, $height);
} else {
$width = $width;
$height = $h / $w * $width;
$imageObj->resize($width, $height);
}
$imageObj->save($pathBaseDir);
} catch (Exception $e) {
}
}
return $this->getPlaceholder();
}
示例14: addImage
protected function addImage($url, $height = null, $weight = null)
{
$ext = array_reverse(explode(".", $url));
$ext = $ext[0];
$name = basename($url, "." . $ext);
$tempFileName = Mage::getBaseDir('tmp') . "/{$name}" . time() . ".png";
switch ($ext) {
case 'gif':
imagepng(imagecreatefromgif($url), $tempFileName);
break;
case 'jpg':
imagepng(imagecreatefromjpeg($url), $tempFileName);
break;
case 'png':
file_put_contents($tempFileName, file_get_contents($url));
break;
default:
return 0;
}
$this->_tmpFiles[] = $tempFileName;
$_image = new Varien_Image($tempFileName);
$_image->keepAspectRatio(true);
//$_image->keepFrame(true);
$_image->keepTransparency(true);
if ($height && $_image->getOriginalHeight() > $height) {
$_image->resize(null, $height);
}
if ($weight && $_image->getOriginalWidth() > $weight) {
$_image->resize($weight, null);
}
$_image->save($tempFileName);
$img = Zend_Pdf_Image::imageWithPath($tempFileName);
$this->_currentPage->drawImage($img, $this->getX(), $this->getY() - $_image->getOriginalHeight(), $this->getX() + $_image->getOriginalWidth(), $this->getY());
$this->setY($this->getY() - $_image->getOriginalHeight() - $this->getInterval());
}
示例15: cropResizeImg
public function cropResizeImg($fileName, $tmp, $width, $height = '')
{
$folderURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
$imageURL = $folderURL . $fileName;
$basePath = $tmp;
$newPath = Mage::getBaseDir() . DS . 'skin' . DS . 'adminhtml' . DS . 'base' . DS . 'default' . DS . 'evoque' . DS . 'images' . DS . 'Configsets' . DS . $fileName;
if (is_file($tmp)) {
$imageObj = new Varien_Image($basePath);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(FALSE);
$imageObj->keepFrame(FALSE);
$currentRatio = $imageObj->getOriginalWidth() / $imageObj->getOriginalHeight();
$targetRatio = $width / $height;
if ($targetRatio > $currentRatio) {
$imageObj->resize($width, null);
} else {
$imageObj->resize(null, $height);
}
$diffWidth = $imageObj->getOriginalWidth() - $width;
$diffHeight = $imageObj->getOriginalHeight() - $height;
//$imageObj->resize($width, $height);
$imageObj->crop(floor($diffHeight * 0.5), floor($diffWidth / 2), ceil($diffWidth / 2), ceil($diffHeight * 0.5));
$imageObj->save($newPath);
}
return $fileName;
}