Skip to content

Commit

Permalink
Only check "gdMaxImgWidth" and "gdMaxImgHeight" if the GDlib is used …
Browse files Browse the repository at this point in the history
…to resize images (see #826).
  • Loading branch information
leofeyer committed Jun 9, 2017
1 parent fca7033 commit 933f9f4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

### DEV

* Only check "gdMaxImgWidth" and "gdMaxImgHeight" if the GDlib is used to resize images (see #826).
* Improve the accessibility of the CAPTCHA widget (see contao/core#8709).
* Re-add the "reset selection" buttons to the picker (see #856).
* Trigger all the callbacks in the toggleVisibility() methods (see #756).
Expand Down
11 changes: 10 additions & 1 deletion src/Resources/contao/classes/DataContainer.php
Expand Up @@ -14,6 +14,7 @@
use Contao\CoreBundle\Exception\AccessDeniedException;
use Contao\CoreBundle\Exception\InternalServerErrorException;
use Contao\Image\ResizeConfiguration;
use Imagine\Gd\Imagine;


/**
Expand Down Expand Up @@ -608,9 +609,17 @@ protected function row($strPalette=null)

if ($objFile->isImage)
{
$blnCanResize = true;

// Check the maximum width and height if the GDlib is used to resize images
if (!$objFile->isSvgImage && \System::getContainer()->get('contao.image.imagine') instanceof Imagine)
{
$blnCanResize = $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth');
}

$image = \Image::getPath('placeholder.svg');

if ($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth'))
if ($blnCanResize)
{
if ($objFile->width > 699 || $objFile->height > 524 || !$objFile->width || !$objFile->height)
{
Expand Down
40 changes: 23 additions & 17 deletions src/Resources/contao/drivers/DC_Folder.php
Expand Up @@ -15,6 +15,7 @@
use Contao\CoreBundle\Exception\ResponseException;
use Contao\CoreBundle\Util\SymlinkUtil;
use Contao\Image\ResizeConfiguration;
use Imagine\Gd\Imagine;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
Expand Down Expand Up @@ -2747,28 +2748,33 @@ protected function generateTree($path, $intMargin, $mount=false, $blnProtected=t
$thumbnail .= ')</span>';

// Generate the thumbnail
if ($objFile->isImage)
if ($objFile->isImage && $objFile->viewHeight > 0 && \Config::get('thumbnails'))
{
if ($objFile->viewHeight > 0)
$blnCanResize = true;

// Check the maximum width and height if the GDlib is used to resize images
if (!$objFile->isSvgImage && \System::getContainer()->get('contao.image.imagine') instanceof Imagine)
{
$blnCanResize = $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth');
}

if ($blnCanResize)
{
if (\Config::get('thumbnails') && ($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth')))
// Inline the image if no preview image will be generated (see #636)
if ($objFile->height !== null && $objFile->height <= 50 && $objFile->width !== null && $objFile->width <= 400)
{
// Inline the image if no preview image will be generated (see #636)
if ($objFile->height !== null && $objFile->height <= 50 && $objFile->width !== null && $objFile->width <= 400)
{
$thumbnail .= '<br><img src="' . $objFile->dataUri . '" width="' . $objFile->width . '" height="' . $objFile->height . '" alt="" style="margin:0 0 2px -18px">';
}
else
{
$thumbnail .= '<br>' . \Image::getHtml(\System::getContainer()->get('contao.image.image_factory')->create(TL_ROOT . '/' . rawurldecode($currentEncoded), array(400, 50, ResizeConfiguration::MODE_BOX))->getUrl(TL_ROOT), '', 'style="margin:0 0 2px -18px"');
}
$thumbnail .= '<br><img src="' . $objFile->dataUri . '" width="' . $objFile->width . '" height="' . $objFile->height . '" alt="" style="margin:0 0 2px -18px">';
}
else
{
$thumbnail .= '<br>' . \Image::getHtml(\System::getContainer()->get('contao.image.image_factory')->create(TL_ROOT . '/' . rawurldecode($currentEncoded), array(400, 50, ResizeConfiguration::MODE_BOX))->getUrl(TL_ROOT), '', 'style="margin:0 0 2px -18px"');
}

$importantPart = \System::getContainer()->get('contao.image.image_factory')->create(TL_ROOT . '/' . rawurldecode($currentEncoded))->getImportantPart();
$importantPart = \System::getContainer()->get('contao.image.image_factory')->create(TL_ROOT . '/' . rawurldecode($currentEncoded))->getImportantPart();

if ($importantPart->getPosition()->getX() > 0 || $importantPart->getPosition()->getY() > 0 || $importantPart->getSize()->getWidth() < $objFile->width || $importantPart->getSize()->getHeight() < $objFile->height)
{
$thumbnail .= ' ' . \Image::getHtml(\System::getContainer()->get('contao.image.image_factory')->create(TL_ROOT . '/' . rawurldecode($currentEncoded), (new ResizeConfiguration())->setWidth(320)->setHeight(40)->setMode(ResizeConfiguration::MODE_BOX)->setZoomLevel(100))->getUrl(TL_ROOT), '', 'style="margin:0 0 2px 0;vertical-align:bottom"');
}
if ($importantPart->getPosition()->getX() > 0 || $importantPart->getPosition()->getY() > 0 || $importantPart->getSize()->getWidth() < $objFile->width || $importantPart->getSize()->getHeight() < $objFile->height)
{
$thumbnail .= ' ' . \Image::getHtml(\System::getContainer()->get('contao.image.image_factory')->create(TL_ROOT . '/' . rawurldecode($currentEncoded), (new ResizeConfiguration())->setWidth(320)->setHeight(40)->setMode(ResizeConfiguration::MODE_BOX)->setZoomLevel(100))->getUrl(TL_ROOT), '', 'style="margin:0 0 2px 0;vertical-align:bottom"');
}
}
}
Expand Down

0 comments on commit 933f9f4

Please sign in to comment.