Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Option NamePossible ValuesWhat it does
orientation
  • manual (default)
  • portrait
  • landscape
  • auto

Right now attempt to resize 768x1024 (portrait) image to the 1024x768 (landscape) size would result in too small image. This behavior is kept with "manual" option.

However when you specify "auto" option, then given resize dimensions are inverted (only when needed) to match portrait/landscape setting of user uploaded image.

output_format
  • jpg
  • png
  • gif
  • bmp
  • auto (default)
Right now the format of user uploaded image is preserved after resize. This option would allow to force resized image to have given format.
quality
  • 0-100 - for jpg
  • 0-9 for png

Right now we're setting maximal quality (based on image format) to reduce distortion in resized images.

With this new setting (in combination with "output_format") it will be possible to have images of desired quality.

Examples

  • <inp2:u_Field name="PrimaryImage" format="resize:800x600;orientation:auto"/> - will adjust resize dimensions based on source image orientation
  • <inp2:u_Field name="PrimaryImage" format="resize:800x600;output_format:jpg"/> - will convert image to jpg preserving maximal image quality
  • <inp2:u_Field name="PrimaryImage" format="resize:800x600;output_format:jpg;quality:70"/> - will convert image to jpg with 70% image quality (default setting in Photoshop when saving jpg files)
  • <inp2:u_Field name="PrimaryImage" format="resize:800x600;quality:70"/> - will convert image, but will apply 70 number as-is to the quality parameter, which will result in broken png image (when png is uploaded)

Solution

Plan (part 1 - support for "quality" option)

...

  1. in "ImageHelper::parseFormat" method parse "orientation:X" format: - 0.5h
    • the "X" is a string from this list: auto, manual, portrait, landscape
    • when "X" happens to be something else throw an exception
    • the "$res" array would initially contain array('orientation' => 'manual')
  2. add protected "ImageHelper::shouldRotateDimensions($src_image, $dst_width, $dst_height, array $params)" method, that will: - 0.5h
    • store $params['orientation'] into $orientation variable
    • if $orientation is "manual", then return "false"
    • if $orientation is "auto", but only one of $dst_width/$dst_height is a number, then throw an exception
    • if $orientation is "auto", then set $resized_orientation variable to orientation ("portrait" or "landscape") based on $dst_width and $dst_height variable values
    • otherwise set $resized_orientation variable to value of $orientation variable (at this point it could be only "portrait" or "landscape")
    • get image dimensions of "$src_image" image using "\ImageHelper::getImageInfo" method
    • set $src_image_orientation variable to orientation ("portrait" or "landscape") of $src_image based on above retrieved image dimensions and store it into 
    • return true, when $src_image_orientation doesn't match $resized_orientation
    • return false otherwise
  3. in "ImageHelper::ResizeImage" method, when "orientation" is "auto" AND we're inside if ( !$this->isSVG($src_image) && ($params['max_width'] > 0 || $params['max_height'] > 0) ) { logic branch (as 1st thing): - 0.5h
    • if "ImageHelper::shouldRotateDimensions" returns thrusy value, then:
      • swap "$params['max_width']" and "$params['max_height']" values
      • swap "$params['crop_x']" and "$params['crop_y']" values, but only when such keys exist

Quote: 4h*1.4 = 6h

Related Discussions

Related Tasks

Jira Legacy
serverSystem Jira
serverId513b375f-8291-3313-9d9f-704c39b1f915
keyINP-1668