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 dimension width height

Former Member
0 Likes
2,208

Hi all,

I am uploading a JPG image file in GUI and I need to validate its dimension. Is there any function module that I can use to get the width and height?

Thanks.

1 ACCEPTED SOLUTION
Read only

Clemenss
Active Contributor
0 Likes
1,304

Hi Felipe,

I don't know any function module or class method for this - though it may exist.

As I just found out, JPEG structure is (in most cases) pretty simple. The JPEG files contains some identifiers starting a defined structure.

Put the uploaded JPEG into an XSTRING field, search for start-of-frame 0 identifier followed by lenght and data precision constant 'FFC0001108'. This constant is followed by two unsigned integers for height and width. If you found this offset, assign xstringoffset(2) to shortint height variable, add 2 to offset and assign xstringoffset(2) to shortint width variable.

As we do not have 2-byte unsigned integers we will move the first byte to an INT1 variable Hbyte, second byte to INT1 variable Lbyte and get the result as Hbyte * 256 + Lbyte.

I found information on [Getting JPG dimensions with AS3 without loading the entire file|http://www.anttikupila.com/flash/getting-jpg-dimensions-with-as3-without-loading-the-entire-file/] in non-ABAP language. Give it a try.

Regards,

Clemens

4 REPLIES 4
Read only

Clemenss
Active Contributor
0 Likes
1,305

Hi Felipe,

I don't know any function module or class method for this - though it may exist.

As I just found out, JPEG structure is (in most cases) pretty simple. The JPEG files contains some identifiers starting a defined structure.

Put the uploaded JPEG into an XSTRING field, search for start-of-frame 0 identifier followed by lenght and data precision constant 'FFC0001108'. This constant is followed by two unsigned integers for height and width. If you found this offset, assign xstringoffset(2) to shortint height variable, add 2 to offset and assign xstringoffset(2) to shortint width variable.

As we do not have 2-byte unsigned integers we will move the first byte to an INT1 variable Hbyte, second byte to INT1 variable Lbyte and get the result as Hbyte * 256 + Lbyte.

I found information on [Getting JPG dimensions with AS3 without loading the entire file|http://www.anttikupila.com/flash/getting-jpg-dimensions-with-as3-without-loading-the-entire-file/] in non-ABAP language. Give it a try.

Regards,

Clemens

Read only

Former Member
0 Likes
1,304

solved, Thanks Clemens

Edited by: Felipe Grajales on Jul 11, 2011 4:41 PM

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,304

Hi,

I think you can use IGS (depending on your SAP release). IMGCONV tool can be reached through CL_IGS_IMAGE_CONVERTER, where you can get attributes HEIGHT and WIDTH. To be tested.

More info: http://help.sap.com/saphelp_nw70/helpdata/en/17/86c039c7811f11e10000000a114084/frameset.htm

Search SDN too.

BR

Sandra

Read only

1,304

Check this code snippet. Not tested on all picture formats, but jp(e)g works well.
Under hood works the IGS, but this nice encapsulation does the job.


DATA:
  mimetype        TYPE string,
  xres            TYPE i,
  yres            TYPE i,
  xdpi            TYPE i,
  ydpi            TYPE i,
  bitdepth        TYPE i,
  image_processor TYPE REF TO cl_fxs_image_processor.

image_processor = NEW #( ).

DATA(handle) = image_processor->add_image_from_url( iv_url = '<real url pointing to an image>').

image_processor->get_info( EXPORTING iv_handle   = handle
                           IMPORTING ev_mimetype = mimetype
                                     ev_xres     = xres
                                     ev_yres     = yres
                                     ev_xdpi     = xdpi
                                     ev_ydpi     = ydpi
                                     ev_bitdepth = bitdepth ).