-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Remove dependency on Exif parsing library. #2947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 12 additions & 36 deletions
48
app/src/main/java/fr/free/nrw/commons/upload/EXIFReader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,36 @@ | ||
package fr.free.nrw.commons.upload; | ||
|
||
import com.drew.imaging.ImageMetadataReader; | ||
import com.drew.imaging.ImageProcessingException; | ||
import com.drew.metadata.Directory; | ||
import com.drew.metadata.Metadata; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import androidx.exifinterface.media.ExifInterface; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import fr.free.nrw.commons.utils.ImageUtils; | ||
import io.reactivex.Single; | ||
import timber.log.Timber; | ||
|
||
/** | ||
* We try to avoid copyright violations in commons app. | ||
* For doing that we read EXIF data using the library metadata-reader | ||
* If an image doesn't have any EXIF Directoris in it's metadata then the image is an | ||
* internet download image(and not the one taken using phone's camera) */ | ||
|
||
* We try to minimize uploads from the Commons app that might be copyright violations. | ||
* If an image does not have any Exif metadata, then it was likely downloaded from the internet, | ||
* and is probably not an original work by the user. We detect these kinds of images by looking | ||
* for the presence of some basic Exif metadata. | ||
*/ | ||
@Singleton | ||
public class EXIFReader { | ||
@Inject | ||
public EXIFReader() { | ||
//Empty | ||
} | ||
/** | ||
* The method takes in path of the image and reads metadata using the library metadata-extractor | ||
* And the checks for the presence of EXIF Directories in metadata object | ||
* */ | ||
|
||
public Single<Integer> processMetadata(String path) { | ||
Metadata readMetadata = null; | ||
try { | ||
readMetadata = ImageMetadataReader.readMetadata(new File(path)); | ||
} catch (ImageProcessingException e) { | ||
Timber.d(e.toString()); | ||
} catch (IOException e) { | ||
Timber.d(e.toString()); | ||
} | ||
if (readMetadata != null) { | ||
for (Directory directory : readMetadata.getDirectories()) { | ||
// In case of internet downloaded image these three fields are not present | ||
if (directory.getName().equals("Exif IFD0") //Contains information about the device capturing the photo | ||
|| directory.getName().equals("Exif SubIFD") //contains information like date, time and pixels of the image | ||
|| directory.getName().equals("Exif Thumbnail")) //contains information about image thumbnail like compression and reolution | ||
{ | ||
Timber.d(directory.getName() + " Contains metadata"); | ||
return Single.just(ImageUtils.IMAGE_OK); | ||
} | ||
ExifInterface exif = new ExifInterface(path); | ||
if (exif.getAttribute(ExifInterface.TAG_MAKE) != null | ||
|| exif.getAttribute(ExifInterface.TAG_DATETIME) != null) { | ||
return Single.just(ImageUtils.IMAGE_OK); | ||
} | ||
} catch (Exception e) { | ||
return Single.just(ImageUtils.FILE_NO_EXIF); | ||
} | ||
return Single.just(ImageUtils.FILE_NO_EXIF); | ||
} | ||
|
||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While removing a 656 KB library is great, in my humble opinion I would say that this implementation is much less readable, replacing easy-to-read business logic with byte manipulation and unexplained magic codes such as "8BIM" and 0x80.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe some comments/explanations could help. In that case would you still think this is less readable @nicolas-raoul ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dbrant is it possible to add some comments here to make it more readable?