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

Get image resolution from binary (xstring) image

Former Member
0 Likes
3,055

Hi,

is it possible to get the resolution of an image in ABAP?

Simplified scenario:

- Users can upload images via portal

- I will get the uploaded image as xstring within my ABAP coding

Now I like to check the resolution of an uploaded image. e.g. if the pixel image size is 1024x800.

Is this possible? If yes for which file types? (TIF, BMP, JPG, GIF)?

If it is not possible to check the resolution in ABAP I think I have to use some 3rd party software like ImageMagic (but then the handling will be more complicated)

Thanks and regards

Tom

5 REPLIES 5
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,822

Hi,

You might try with IGS = Internet Graphics Server (see forum and SAP Library for more information); probably these 4 image formats you mentioned are supported. The main class (CL_IGS_IMAGE_CONVERTER) has attributes WIDTH and HEIGHT, I guess they do what they mean...

For TIFF, there were also old program/transaction (RSTXLDMC/SE78) which were able to decode them.

For BMP, Thomas Jung had written a blog/a class for handling BMPs (but you won't get support in case there are issues), with also some possible format conversions, based on IGS.

Sandra

Read only

0 Likes
1,822

The ideal would be to extract the info directly from the jpeg stream without converting to bitmap, but as a workaround you can convert the image with CL_IGS_IMAGE_CONVERTER and to "borrow" some code from Thomas Jung's Class to get the image properties:

DATA lx_width(4) TYPE x.
DATA lx_height(4) TYPE x.
DATA lx_str TYPE xstring.
DATA lv_width TYPE i.
DATA lv_height TYPE i.
DATA lr_igs_imgconv TYPE REF TO cl_igs_image_converter.
DATA lt_img_blob    TYPE w3mimetabtype.
DATA lv_img_size    TYPE w3param-cont_len.
DATA lx_bmp_xstream TYPE xstring.


*     Get Width and Height of jpeg image as lv_xtring (type xstring)


       CREATE OBJECT lr_igs_imgconv.
       lv_img_size = XSTRLEN( lv_xstring ).
       CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
         EXPORTING
           buffer     = lv_xstring
         TABLES
           binary_tab = lt_img_blob.

       CALL METHOD lr_igs_imgconv->set_image
         EXPORTING
           blob      = lt_img_blob
           blob_size = lv_img_size.

       lr_igs_imgconv->input  = 'image/jpeg'.
       lr_igs_imgconv->output = 'image/x-ms-bmp'.

       CALL METHOD lr_igs_imgconv->execute
         EXCEPTIONS
           OTHERS = 1.


       IF sy-subrc IS INITIAL.

         CALL METHOD lr_igs_imgconv->get_image
           IMPORTING
             blob      = lt_img_blob
             blob_size = lv_img_size.

         CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
           EXPORTING
             input_length = lv_img_size
           IMPORTING
             buffer       = lx_bmp_xstream
           TABLES
             binary_tab   = lt_img_blob
           EXCEPTIONS
             failed       = 1
             OTHERS       = 2.

         lx_width = lx_bmp_xstream+18(4).
         lx_height = lx_bmp_xstream+22(4).
         CONCATENATE lx_width+3(1) lx_width+2(1) lx_width+1(1) lx_width+0(1) INTO lx_str IN BYTE MODE.
         lv_width = lx_str.
         CONCATENATE lx_height+3(1) lx_height+2(1) lx_height+1(1) lx_height+0(1) INTO lx_str IN BYTE MODE.
         lv_height = lx_str.


ENDIF.

Read only

0 Likes
1,822

hello,

If I'm not wrong (I didn't test), there's a just one mistake about the Endianness of the X to I conversion, that is, it works only in a Little Endian system. I also see the same code in Thomas blog, so I jump to there to post the same comment (+ one part of the correction).

Sandra

Read only

Former Member
0 Likes
1,822

You can use the Static method of the Class CL_FXS_IMAGE_INFO=>DETERMINE_INFO.  You need to pass Image as Xstring. In return you will get Image Mime Type & Resolutions(Size).

Read only

0 Likes
1,822

Hi Gaurav,

I have used approach with the Class CL_FXS_IMAGE_INFO and it works great! Thanx a lot for the information.

However, this class comes only up certain release (in System with ABAP 7.00 SP 16 it is not present).

Could you tell me, from which release this class is part of the system? Or a way how to find out?

Thank you in advance!

O.