Skip to content

Commit

Permalink
Partial fix for image resolution on mobile devices (method=resize) - v…
Browse files Browse the repository at this point in the history
…eda-consulting-company#50. Needs to be pushed to v2.x as well.
  • Loading branch information
deepak-srivastava committed Mar 1, 2017
1 parent 203906e commit 1b9488f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion CRM/Mosaico/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,17 +427,27 @@ static function getAllMetadata()
*/
static function resizeImage( $file_name, $method, $width, $height )
{
$mobileMinWidth = 246;
$config = self::getConfig();

$image = new Imagick( $config['BASE_DIR'] . $file_name );

if ( $method == "resize" )
{
$resize_width = $width;
$resize_height = $image->getImageHeight();
if ($width < $mobileMinWidth) {
// DS: resize images to higher resolution, for images with lower width than needed for mobile devices
// DS: FIXME: only works for 'resize' method, not 'cover' methods.
// Partially resolves - https://github.com/veda-consulting/uk.co.vedaconsulting.mosaico/issues/50
$resize_width = $resize_width * 2;
$resize_height = $resize_height * 2;
}
// We get 0 for height variable from mosaico
// In order to use last parameter(best fit), this will make right scale, as true in 'resizeImage' menthod, we can't have 0 for height
// hence retreiving height from image
// more details about best fit http://php.net/manual/en/imagick.resizeimage.php
$image->resizeImage( $width, $image->getImageHeight(), Imagick::FILTER_LANCZOS, 1.0, TRUE );
$image->resizeImage( $resize_width, $resize_height, Imagick::FILTER_LANCZOS, 1.0, TRUE );
}
else // $method == "cover"
{
Expand Down

0 comments on commit 1b9488f

Please sign in to comment.