Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Uploaded files should now be resized correctly (see #3806)
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Mar 26, 2012
1 parent 09b5ff5 commit 5e92113
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Contao Open Source CMS Changelog
Version 2.11.3 (XXXX-XX-XX)
---------------------------

### Fixed
Uploaded files should now be resized correctly (see #3806).

### Fixed
Fixed the "setCookie" hook (see #4116).

Expand Down
28 changes: 15 additions & 13 deletions system/modules/backend/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,28 +283,30 @@ protected function resizeUploadedImage($strImage)
return false;
}

$blnResized = false;
$blnResize = false;

// The image exceeds the maximum image height
if ($arrImageSize[1] > $GLOBALS['TL_CONFIG']['imageHeight'])
// The image exceeds the maximum image width
if ($arrImageSize[0] > $GLOBALS['TL_CONFIG']['imageWidth'])
{
$blnResized = true;
$this->resizeImage($strImage, 0, $GLOBALS['TL_CONFIG']['imageHeight']);

// Recalculate the image size
$arrImageSize = @getimagesize(TL_ROOT . '/' . $strImage);
$blnResize = true;
$intWidth = $GLOBALS['TL_CONFIG']['imageWidth'];
$intHeight = ceil($GLOBALS['TL_CONFIG']['imageWidth'] * $arrImageSize[1] / $arrImageSize[0]);
$arrImageSize = array($intWidth, $intHeight);
}

// The image exceeds the maximum image width
if ($arrImageSize[0] > $GLOBALS['TL_CONFIG']['imageWidth'])
// The image exceeds the maximum image height
if ($arrImageSize[1] > $GLOBALS['TL_CONFIG']['imageHeight'])
{
$blnResized = true;
$this->resizeImage($strImage, $GLOBALS['TL_CONFIG']['imageWidth'], 0);
$blnResize = true;
$intWidth = ceil($GLOBALS['TL_CONFIG']['imageHeight'] * $arrImageSize[0] / $arrImageSize[1]);
$intHeight = $GLOBALS['TL_CONFIG']['imageHeight'];
$arrImageSize = array($intWidth, $intHeight);
}

// Resized successfully
if ($blnResized)
if ($blnResize)
{
$this->resizeImage($strImage, $arrImageSize[0], $arrImageSize[1]);
$this->addInfoMessage(sprintf($GLOBALS['TL_LANG']['MSC']['fileResized'], $strName));
$this->log('File "'.$strName.'" uploaded successfully and was scaled down to the maximum dimensions', 'Uploader resizeUploadedImage()', TL_FILES);
$this->blnHasResized = true;
Expand Down

0 comments on commit 5e92113

Please sign in to comment.