Rotation and crop PNG image data using pure Java -- 2
Budget: $65 – $100 USD
We just implemented an API where we download UPS labels and tracking information as part of a JSON response to an HTTPS Restful request. This is on a DESKTOP PC (not a web server) and the image is coming in from UPS in Landscape, 7 inches wide, by 4 inches tall ( 1400 x 800 pixels, 200 dpi).
We want you to rotate the image 90 degrees to the right, so we can print the image on a thermal label printer in portrait mode, as well as possible cropping the image to 1200 pixels of the original 1400.
I will share the existing code for handling the conversion of the JSON response, in Base64 into a binary string, and what I found in researching image cropping and rotation in Java.
Notice the 2nd to last line of code:
byte[] image = Base64.getDecoder().decode(imageData);
Your job is to rotate "image" 90 degrees to the right. You will see what I found in PictureUtils.java
=====================================================
FULL CODE TO EXTRACT ONE OR MORE PNG LABELS - One PNG per tracking # / carton
=====================================================
Iterator itLabel = LabelData.iterator();
itTrack = TrackingInfo.iterator();
for ( int i = 1; itLabel.hasNext(); ++i )
{
JSONObject track = (JSONObject) itTrack.next();
String tid = (String) track.get("TrackingNumber");
JSONObject label = (JSONObject) itLabel.next();
String imageData = (String) label.get("Content");
byte[] image = Base64.getDecoder().decode(imageData);
AppUtil.writeImageToDisk(tid + fileExt, fileDir, "", image);
}
We want you to rotate the image 90 degrees to the right, so we can print the image on a thermal label printer in portrait mode, as well as possible cropping the image to 1200 pixels of the original 1400.
I will share the existing code for handling the conversion of the JSON response, in Base64 into a binary string, and what I found in researching image cropping and rotation in Java.
Notice the 2nd to last line of code:
byte[] image = Base64.getDecoder().decode(imageData);
Your job is to rotate "image" 90 degrees to the right. You will see what I found in PictureUtils.java
=====================================================
FULL CODE TO EXTRACT ONE OR MORE PNG LABELS - One PNG per tracking # / carton
=====================================================
Iterator itLabel = LabelData.iterator();
itTrack = TrackingInfo.iterator();
for ( int i = 1; itLabel.hasNext(); ++i )
{
JSONObject track = (JSONObject) itTrack.next();
String tid = (String) track.get("TrackingNumber");
JSONObject label = (JSONObject) itLabel.next();
String imageData = (String) label.get("Content");
byte[] image = Base64.getDecoder().decode(imageData);
AppUtil.writeImageToDisk(tid + fileExt, fileDir, "", image);
}