Skip to content

Added metadata reader for reading exif data #2581

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 10 commits into from
Mar 19, 2019

Conversation

vanshikaarora
Copy link
Contributor

Reading EXIF Directories Exif IFD0, Exif SubIFD, Exif Thumbnail if it does not contains any of these disaplay a warning to the user

Fixes #97 Avoid copyright violations

Changes Made

  • Added a class(ReadExif.java) to read exif data
  • Modifies ImageUtils.java
  • Modified ImageProcessingService.java

@vanshikaarora
Copy link
Contributor Author

@maskaravivek @nicolas-raoul Can you please review this PR. It will help in working out with #2542

import timber.log.Timber;

@Singleton
public class ReadEXIF {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for using a verb rather than a noun (which is the convention for Java classes)?
I would suggest EXIFReader.


}

public Single<Integer> processMetadata(String path) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javadoc

@vanshikaarora
Copy link
Contributor Author

@nicolas-raoul I have made the changes. Kindly review :)

@codecov-io
Copy link

codecov-io commented Mar 18, 2019

Codecov Report

Merging #2581 into master will increase coverage by <.01%.
The diff coverage is 28%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2581      +/-   ##
=========================================
+ Coverage    2.77%   2.77%   +<.01%     
=========================================
  Files         259     261       +2     
  Lines       12373   12451      +78     
  Branches     1117    1130      +13     
=========================================
+ Hits          343     346       +3     
- Misses      12003   12078      +75     
  Partials       27      27
Impacted Files Coverage Δ
...ain/java/fr/free/nrw/commons/utils/ImageUtils.java 0% <ø> (ø) ⬆️
...in/java/fr/free/nrw/commons/upload/EXIFReader.java 0% <0%> (ø)
...ree/nrw/commons/upload/ImageProcessingService.java 85.48% <100%> (+0.73%) ⬆️
...n/java/fr/free/nrw/commons/CommonsApplication.java 0% <0%> (ø) ⬆️
...e/nrw/commons/category/CategoryImagesActivity.java 0% <0%> (ø) ⬆️
...rw/commons/mwapi/ApacheHttpClientMediaWikiApi.java 0% <0%> (ø) ⬆️
...r/free/nrw/commons/contributions/MainActivity.java 0% <0%> (ø) ⬆️
...java/fr/free/nrw/commons/upload/UploadService.java 0% <0%> (ø) ⬆️
...ava/fr/free/nrw/commons/upload/UploadActivity.java 0% <0%> (ø) ⬆️
...rw/commons/explore/categories/ExploreActivity.java 0% <0%> (ø) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 341f961...1c509d6. Read the comment docs.

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor things :-)


}

public Single<Integer> processMetadata(String path) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javadoc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the doc for this just above the class declaration. Shall I put it above the function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both the class and the method need javadoc. At least say briefly what the method does, and what are the inputs and outputs of the method.

public class EXIFReader {
@Inject
public EXIFReader() {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A common practice is to write // Empty in empty methods so that readers know it is not a mistake :-)

try {
readMetadata = ImageMetadataReader.readMetadata(new File(path));
} catch (ImageProcessingException e) {
e.printStackTrace();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about logging the error to logcat? https://stackoverflow.com/a/8217563/226958

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With Timber I guess.

}
if (readMetadata != null) {
for (Directory directory : readMetadata.getDirectories()) {
if (directory.getName().equals("Exif IFD0") || directory.getName().equals("Exif SubIFD") || directory.getName().equals("Exif Thumbnail")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put each equals on its own line, and add at the end of the line a comment explaining where this kind of directory is usually found.
Otherwise future readers will have a very hard time knowing what it means.
Thanks! :-)

});
return Single.zip(zipResult,checkFBMD,checkEXIF, (zip,fbmd,exif)->{
Timber.d("zip:"+zip+"fbmd:"+fbmd+"exif:"+exif);
return zip| fbmd| exif;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better put a space before |.
For this kind of conventions a good read is https://www.oracle.com/technetwork/java/codeconventions-150003.pdf

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thanks for the resource @nicolas-raoul :)

@vanshikaarora
Copy link
Contributor Author

@nicolas-raoul I have made the changes. Kindly review :)

// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

about Image THumbnail like compression and reolution -> about image thumbnails like compression and resolution

Timber.d("zip:" + zip + "fbmd:" + fbmd);
return zip | fbmd;
});
return Single.zip(zipResult,checkFBMD,checkEXIF, (zip,fbmd,exif)->{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after each comma

return zip | fbmd;
});
return Single.zip(zipResult,checkFBMD,checkEXIF, (zip,fbmd,exif)->{
Timber.d("zip:"+zip+"fbmd:"+fbmd+"exif:"+exif);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space before and after each +

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@ujjwalagrawal17 ujjwalagrawal17 self-requested a review March 19, 2019 13:32
@ujjwalagrawal17 ujjwalagrawal17 merged commit 3417d71 into commons-app:master Mar 19, 2019
@vanshikaarora
Copy link
Contributor Author

Thanks for approving the PR @nicolas-raoul @neslihanturan @ujjwalagrawal17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants