Uploaded image for project: 'In-Portal CMS'
  1. In-Portal CMS
  2. INP-1668

Allow specifying image quality, orientation and output format during resizing

    XMLWordPrintable

    Details

    • Type: Feature Request
    • Status: Accepted
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 5.3.0
    • Component/s: Image Processing
    • Labels:
      None
    • Change Log Group:
      Added
    • Change Log Message:
      Allow specifying image quality, orientation and output format during resizing.
    • Story Points:
      2
    • Copy Issue Key:
    • Patch Instructions:

      Patches must be submitted through Phabricator.

      Description

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

      1. in "ImageHelper::parseFormat" method parse "quality:X" format: - 0.5h
        • the "X" is a number between 0 and 100
        • when "X" happens to be something else throw an exception
        • the "$res" array would initially contain array('quality' => 100)
      2. add protected "ImageHelper::convertQualityToCompression($quality)" method after "ImageHelper::ScaleImage" method that will: - 0.5h
        • subtract value from 100 (when 60 is given it will become 40)
        • divide by 10 and round it (the (100-65)/10 becomes 4)
        • return the result
      3. in "ImageHelper::ScaleImage" method where "$write_function" is used to save file on disk: - 0.5h
        • where "0" is used now (the PNG files) use result of "ImageHelper::convertQualityToCompression" method on "quality" parameter parsed before
        • where "100" is used (everything else) use "quality" parameter parsed before

       

      Plan (part 2 - support for "output_format" option):

      1. in "ImageHelper::parseFormat" method parse "output_format:X" format: - 0.5h
        • the "X" is a string from this list: jpg, png, gif, bmp, auto
        • when "X" happens to be something else throw an exception
        • the "$res" array would initially contain array('output_format' => 'auto')
      2. in "ImageHelper::ScaleImage" method: - 0.5h
        • after "$write_function" variable was defined create "$output_format_map" array, where:
          • key is value for "output_format" option, except "auto"
          • value is 2 last matching elements (also separated by colon) from $resize_map" array (e.g. "imagejpeg:jpg" value for "jpg" key and so on)
        • if "output_format" option isn't "auto", then change "$write_function" and "$file_extension" variables to values extracted from "$output_format_map" array based on used "output_format" option value

       

      Plan (part 3 - support for "orientation" 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 not "manual" 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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                alex Alex
                Reporter:
                alex Alex
                Developer:
                Erik Snarski [Intechnic]
                Reviewer:
                Alex
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Time Tracking

                  Estimated:
                  Original Estimate - 6h Original Estimate - 6h
                  6h
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 10h 56m
                  10h 56m