2

Is there a way through apex or using the VersionData of the ContentVersion for me to change that EXIF data of a ContentVersion image so that it won't register as needing to rotate?

To be more specific, a customer has been using a system where they will upload pictures to the chatter feed of a record, and it will save the image link to the ContentVersion direct download.

We then use that to output the most recent chatter post in some pages, and even in a formula on the custom object.

We found that sometimes when posting pictures from the Salesforce1 app, the pictures are saving in the EXIF metadata that the picture is rotated 90 degrees. This causes the pictures to be rendered sideways in both the formula field, and when rendered in HTML/VisualForce.

I have tried image-orientation on the tag for pages, but it isn't supported in some browsers so I'm at a loss.

2 Answers 2

1

Basically, no, you're not going to do that in Apex Code. Binary data is very challenging to work with and likely to run in to governor limits. You'll probably want to write a Lightning Component or Visualforce page that would use an HTMLCanvas to rotate images that are incorrect, or use an external service written on some platform service.

For example, we have an AWS EB (Amazon Web Service Elastic Beanstalk) that retrieves new images from user uploads, uses Image Magick to scale the images, and then saves them back to Salesforce. You could use a similar principle to design a system that could run on the cloud somewhere to do this processing.

However, with our move to Lightning, we're planning on rewriting this code to run native in the browser to avoid the overhead of maintaining our EB server. This would be done via a canvas that rescales the images and then saves them to the server.

0

Yes you can. refer "JEITA CP-3451 Exchangeable image file format for digital still cameras: Exif Version 2.2"

in APEX

try{
    contentversion CV  =[select id,VersionData from contentversion where id =: photoid limit 1];
    CVvd = EncodingUtil.convertToHex(CV.VersionData);
}
catch (Exception e) {
    System.debug('exeption '+e); 
    Result.add('exception');
    return null;
}
System.debug(CVvd.length()); 
for (Integer k = 0; k < 3000; k++) {            
    dataexif2.add(CVvd.mid(k,2));   
    k=k+1;
}
// EXIF codage little endian 4949
if (dataexif2[0]== 'ff' && dataexif2[1]== 'd8' 
    && dataexif2[2]== 'ff' && dataexif2[3]== 'e1' 
    && dataexif2[6]== '45' && dataexif2[7]== '78' 
    && dataexif2[8]== '69' && dataexif2[9]== '66'
    && dataexif2[10]== '00' && dataexif2[11]== '00'
    && dataexif2[12]== '49'&& dataexif2[13]== '49'
    && dataexif2[14]== '2a'&& dataexif2[15]== '00') {
        // fichier jpeg
 zeroth_IFD_Offset = (integer.valueof(dataexif2[16]))+12; 
        System.debug('zeroth_IFD_Offset '+zeroth_IFD_Offset); 
        System.debug('nombre de champs '+dataexif2[20]); 
            
        // recherche des Pointeurs
        for (integer i= 2+zeroth_IFD_Offset;i<(xsourceHex(dataexif2[20])*12)+zeroth_IFD_Offset; i++) {   
            if (dataexif2[i]+dataexif2[i+1] == '6987' && dataexif2[i+2]=='04' ) {
                //some more code
1
  • Did the last bit of code get inadvertently omitted?
    – cropredy
    Jun 27, 2022 at 14:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .