Jump to content

Exif image


epos4u

Recommended Posts

12 minutes ago, epos4u said:

using UnimFileUpload then display the image in UnimImage, selecting image from phone, camera rotation is not always correct to display

exif to see what the rotation is, so can be rotated in code in UnimImage

Hi,

I will try to analyze.

  • Like 1
Link to comment
Share on other sites

1 hour ago, epos4u said:

i don't mind using UnimFileUploadButton , if you have a solution that would be great

OK. Try these steps...

1. UnimFileUploadButton1

2. CustomFiles: files/orientation.js

function getOrientation(file, callback) {
    var reader = new FileReader();
    reader.onload = function(e) {

        var view = new DataView(e.target.result);
        if (view.getUint16(0, false) != 0xFFD8)
        {
            return callback(-2);
        }
        var length = view.byteLength, offset = 2;
        while (offset < length)
        {
            if (view.getUint16(offset+2, false) <= 8) return callback(-1);
            var marker = view.getUint16(offset, false);
            offset += 2;
            if (marker == 0xFFE1)
            {
                if (view.getUint32(offset += 2, false) != 0x45786966)
                {
                    return callback(-1);
                }

                var little = view.getUint16(offset += 6, false) == 0x4949;
                offset += view.getUint32(offset + 4, little);
                var tags = view.getUint16(offset, little);
                offset += 2;
                for (var i = 0; i < tags; i++)
                {
                    if (view.getUint16(offset + (i * 12), little) == 0x0112)
                    {
                        return callback(view.getUint16(offset + (i * 12) + 8, little));
                    }
                }
            }
            else if ((marker & 0xFF00) != 0xFF00)
            {
                break;
            }
            else
            {
                offset += view.getUint16(offset, false);
            }
        }
        return callback(-1);
    };
    reader.readAsArrayBuffer(file);
}

3. 

  private
     FOrientation: Byte;
    { Private declarations }

4. MainmForm -> OnCreate:

procedure TMainmForm.UnimFormCreate(Sender: TObject);
begin
  UnimFileUploadButton1.JSInterface.JSAddListener('change', 'function(sender){getOrientation(sender.getFiles()[0], function(orientation) {ajaxRequest(sender, "getOrientation", ["orientation="+orientation])})}');
end;

 5. UnimFileUploadButton1 -> OnAjaxEvent:

procedure TMainmForm.UnimFileUploadButton1AjaxEvent(Sender: TComponent;
  EventName: string; Params: TUniStrings);
begin
  if EventName = 'getOrientation' then
  begin
    FOrientation := Params.Values['orientation'].ToInteger;
  end;

end;

 

Orientation values:

VGsAj.gif.62675f98009193cebf69698dae6cfee1.gif

Source: https://stackoverflow.com/questions/7584794/accessing-jpeg-exif-rotation-data-in-javascript-on-the-client-side

Link to comment
Share on other sites

Hi Sherzod,

4. MainmForm -> OnCreate:

procedure TMainmForm.UnimFormCreate(Sender: TObject);
begin
  UnimFileUploadButton1.JSInterface.JSAddListener('change', 'function(sender){getOrientation(sender.getFiles()[0], function(orientation) {ajaxRequest(sender, "getOrientation", ["orientation="+orientation])})}');
end;

does not trigger on complete , not sure why

Link to comment
Share on other sites

2 hours ago, epos4u said:

does not trigger on complete , not sure why

Hi,

Yes, this is another event. When you select a file (take a picture), this event is triggered, in which you store a global variable that stores the last selected orientation of the 'image':

6 hours ago, Sherzod said:

5. UnimFileUploadButton1 -> OnAjaxEvent:


procedure TMainmForm.UnimFileUploadButton1AjaxEvent(Sender: TComponent;
  EventName: string; Params: TUniStrings);
begin
  if EventName = 'getOrientation' then
  begin
    FOrientation := Params.Values['orientation'].ToInteger;
  end;

end;

 

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...