Skip to content
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

feat-4125-compressImage-Function-using-Java #174

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

brinkbrink
Copy link

Checklist:

  • Ask to be assigned to the issue.
  • Implement function compressImage() in Java/ folder.
  • Manually execute the newly implemented function to ensure it works.
  • Submit a pull request in open-runtimes/examples and include screenshots of successful execution.

Closes appwrite/appwrite#4125

Authors: Tin Pham, E. Brink, Ali Sharif.

Summary

This pull request creates a Java function that performs lossless compression on an image by integrating Tinypng and KrakenIO API.

image and provider are recieved from the payload, where image is a base64 encoded string and provider is either tinypng or krakenio

Example input:

{
  "provider": "tinypng",
  "image": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAf0lEQVR4nO2Wuw2AMAxEbw1gpMwDDMBcGQpooDKydGVAoXCK6J7k6qyc83MCCFGP/Yz+CkDF4KHmjgowbQF0CKFrCDUiwztqxabHCL0/xwcNhoI2UdsjC8g0mQvaSs1zwkg0uQAsAEaGm9/UPCeU7eMj6loTEpf6ZOQWMxd98gAhZnS6XEZcNQAAAABJRU5ErkJggg==",
    
}

krakenio is also a supported provider

Example output:

{
    "success": true,
    "image": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAACBVGfHAAAAG1BMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACUUeIgAAAACHRSTlMA8712Sxr5g97cFtUAAAA9SURBVCjPY6Aa6AADfAIcDSA8KoBTgLGVgSFCAEmAqZmBwUIBSYClzTQ4wwE52Cs6OtpR4oFFUciBerEKAP58HnyLtZsYAAAAAElFTkSuQmCC"
}

Details

README.md contains instructions on how to run the main function.

Testing

Kraken Input:

{"provider":"krakenio","image":"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAdgAAAHYBTnsmCAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAEoSURBVDiNpdM9K4VhGAfw33kOJSTOUVIGFhNFFjux+AiOMlkVFouMFmWVfAeDQcoHUAbFwBmwGZwn8hblZXhu9Xg6Ogf/urq77v/Vdd//64V/Ipfxm1FEJ6LgwxPecYNK8L9hBmV81GlllKABU9jCCg7wGOw2nNCC9nC2YAzbqOSwg2vM/VL+Jroi9OI0Q7ZhH1dYQGOVBCfojSRFq2TICYxgHcs4xmgmpoJChALiDNmKO2ygH4fYQ1MqJv5KUAsR8pI2flQj4/CLNJ4lVV/CGYYwiZdUTAFxFLQUMwl2cSTpzCqGg4w0iogbcImBDPmA8RrSBnGRxz3WJBpf0SEZlly4y0va2o0e9GEW81j8ylbCufpH+RzT/LxMxfByepneJPWqukx/xienmFIUmYAfWAAAAABJRU5ErkJggg=="}

KrakenIO Output:

{
    "image": "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAA2UlEQVQoz43RsUpCARQG4G8oC4lAotHB3UERssUHsBoDBzV6Ah2iofJFsiXoBbpzvYQEDRpE1JrSYEN3qKGLt4tX6ZzpP+eH\/z\/n55+VlVdWUVNTUZaXjZdHRr5TeqQNB76cqSoqyMnIyCkoqjoX2iNwuVC4L2CgE8FNd16cWJ0ROga8aUbw0FjXu0e70aTplU\/1CB57xpZrH9ZB3XSesO3GxFpMiCUaJk6NPdj5KxGb3HDvSddK0mSgv\/DMK7fsC12kPqon\/PXXNkx99VArGVZpFlYpGdbS+gEbwUrem16hIgAAAABJRU5ErkJggg==",
    "success": true
}

output of kraken api

TinyPNG Input:

{"provider":"tinypng","image":"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAdgAAAHYBTnsmCAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAEoSURBVDiNpdM9K4VhGAfw33kOJSTOUVIGFhNFFjux+AiOMlkVFouMFmWVfAeDQcoHUAbFwBmwGZwn8hblZXhu9Xg6Ogf/urq77v/Vdd//64V/Ipfxm1FEJ6LgwxPecYNK8L9hBmV81GlllKABU9jCCg7wGOw2nNCC9nC2YAzbqOSwg2vM/VL+Jroi9OI0Q7ZhH1dYQGOVBCfojSRFq2TICYxgHcs4xmgmpoJChALiDNmKO2ygH4fYQ1MqJv5KUAsR8pI2flQj4/CLNJ4lVV/CGYYwiZdUTAFxFLQUMwl2cSTpzCqGg4w0iogbcImBDPmA8RrSBnGRxz3WJBpf0SEZlly4y0va2o0e9GEW81j8ylbCufpH+RzT/LxMxfByepneJPWqukx/xienmFIUmYAfWAAAAABJRU5ErkJggg=="}

TinyPNG Output:

{
    "image": "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAZlBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwbJTWAAAAIXRSTlMAXDEfBm5JEgv27tvRN+Sxmj0s4Lx7eXRgS\/DVo6BXVDhCV9reAAAAe0lEQVQY021P2RKEIAwrtxTwXHXdU\/7\/JwU8ZzAvmWaaNIU7FIzSpqGUFWkkxh8wBGDSg2uZ4lyx1g1eQlVf3XUFVsSURzfyKAgLJQn8R4HvOQaWoGXgZwfq+wo7Up\/CB5OwWn44onXJsocasYXmZyffn8V6L7Pq2XMZFmhUCEnCfrHCAAAAAElFTkSuQmCC",
    "success": true
}

output of tinypng api

Size testing results:

size test results

tinpham5614 and others added 29 commits July 26, 2023 15:47
…ssion-method

API key and import statement added
change image type in requestBody to png
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.

⚡ Write a compressImage() Function using Java
3 participants