Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Height and width in cl_fxs_image_processor

DaniEmmenegger
Explorer
0 Likes
4,265

hey all

I use class cl_fxs_image_processor to resize some png-files in my system. But I've a problem with pictures in portrait mode.

Example:

Picture has a height of 4624px and a width of 2084px

But cl_fxs_image_processor=>get_info states xres = 4624 and yres = 2048 which isn't correct... as a consequence the resized picture is mailed rotated...

How can I get the right information of my XSTRING-Picture?

Or can I get EXIF-information out of the xstring to change X and y myself?

Any other hints?

importing if_original type xstringval
returning rf_small type xtringval  

METHOD resize4mail.

    TRY.
        DATA(lo_image) = NEW cl_fxs_image_processor( ).
        DATA(lf_handle) = lo_image->add_image( if_original ).

        lo_image->get_info(
          EXPORTING
            iv_handle   = lf_handle
          IMPORTING
            ev_xres     = DATA(lf_xres)
            ev_yres     = DATA(lf_yres) ).

        "Neue Höhe berechnen... Verhältnis beibehalten
        DATA(lf_ratio) = lf_xres / lf_yres.
        DATA(lf_xres_new) = cc_xres_mail. "1024
        IF lf_xres_new >= lf_xres.
          rf_small = if_original.
          lo_image->discard_image( lf_handle ).
          FREE lo_image.
          RETURN.
        ENDIF.
        DATA(lf_yres_new) = lf_xres_new / lf_ratio.

        lo_image->resize(
          EXPORTING
            iv_handle = lf_handle
            iv_xres   = lf_xres_new
            iv_yres   = lf_yres_new ).

        rf_small = lo_image->get_image( lf_handle ).

        lo_image->discard_image( lf_handle ).
        FREE lo_image.

      CATCH cx_root.
        ASSERT 1 = 2.
    ENDTRY.
  ENDMETHOD.

Regards,

Daniel

yes i know... very strange.

The pics are taken by mobile phone and uploaded via an Fiori App. If I display the same picture also on an app, it isn't rotated. If I send the mail without resizing it, it isn't rotated... just if I call method get_info the values are switched and the picture is rotated after resizing it.

6 REPLIES 6
Read only

Sandra_Rossi
Active Contributor
3,431

No problem for me with portrait image, I get correctly x=529, y=849.

Read only

DaniEmmenegger
Explorer
0 Likes
3,431

yes i know... very strange.

The pics are taken by mobile phone and uploaded via an Fiori App. If I display the same picture also on an app, it isn't rotated. If I send the mail without resizing it, it isn't rotated... just if I call method get_info the values are switched and the picture is rotated after resizing it.

Read only

FredericGirod
Active Contributor
3,431

I have used it here, and no problem with all image. Code is little bit long & protected to publish it

but looks like your

  METHOD convertit_taille_image.
    DATA(lv_nouvelle_taille_x) = get_taille_x_image( iv_image_id ) / iv_facteur_conversion.
    DATA(lv_nouvelle_taille_y) = get_taille_y_image( iv_image_id ) / iv_facteur_conversion.
    TRY.
        go_image_processor->resize( iv_handle = iv_image_id
                                    iv_xres   = CONV i( lv_nouvelle_taille_x )
                                    iv_yres   = CONV i( lv_nouvelle_taille_y ) ).
      CATCH cx_sy_range_out_of_bounds .
        rv_image_data = go_image_processor->get_image(  iv_image_id ).
    ENDTRY.
    rv_image_data = go_image_processor->get_image(  iv_image_id ).
  ENDMETHOD.

with french comment, it works better 😉

Read only

DaniEmmenegger
Explorer
3,431

Unfortunately, the issue is known. The class is obsolete.

Hello Daniel,
regarding the problem of the lost orientiation of the image: this problem happens when using CL_FXS_IMAGE_PROCESSOR->ADD_IMAGE() as well as with method ->RESIZE().

1. Method ADD_IMAGE()
With the call of method ADD_IMAGE() the metadata (width, height, color depth) are read from the JPEG marker'SOF' in the image file. The orientation of the image is not part of that JPEG marker. The orientation of the image are part of the EXIF meta data but these are ignored and get lost when an image is 'added' with method ADD_IMAGE()

2. Method RESIZE()
Resizing is based on the IGS(Internet Graphics Service). This uses internally the libjpeg library which itself doesn't support EXIF data in the version which is used by IGS. So during scaling the EXIF data are removed completely from the image.
Unfortunately IGS is also a very old component and will not be updated.
Regarding the support of package S_XSLFO: the features of packages S_XSLFO* and S_XSL_FO* was never released for external development. Both packages were part of a bigger project of which the development was stopped many years ago. Unfortunately this was not communicated well and therefore we released SAP note 
https://launchpad.support.sap.com/#/notes/3073421
to describe the current support for the different OOXML packages. For compatibility reasons we were also not able to fully rearrange the different packages to S_OOXML_DEPRECATED because such changes would lead to warnings/errors in our QA systems because the affected releases were shipped already. So as of SAP_BASIS release 753 the package S_XSLFO is also part of S_OOXML_DEPRECATED.

Best regards,
SAP Development Support

And theres no supported api to resize pictures:

Hello Daniel, 
unfortunately we are not aware of any supported ABAP API for resizing images or other image processing functionality. So we are sorry but we cannot give you a solution. 

Best regards, 
SAP Development Support 

So... if someone has an idea... I would be happy 🙂

Read only

0 Likes
3,431

external tool like Image Magick https://imagemagick.org/index.php

Read only

smn-kr
Discoverer
0 Likes
3,431

I believe your only option is to work around the problem.

Girods suggestion (Image Magick) only works if you have a on-premise sap system.

We solved this problem by resizing the image in our SAP UI5 Application with canvas.

Depending on your use-case you might want to check if you can resize the image with css in your email.