Skip to content

Feat 4122 compressImage python - #159

Closed
rubynguyen1510 wants to merge 4 commits into
open-runtimes:mainfrom
rubynguyen1510:feat-4122-compress-image-python
Closed

Feat 4122 compressImage python#159
rubynguyen1510 wants to merge 4 commits into
open-runtimes:mainfrom
rubynguyen1510:feat-4122-compress-image-python

Conversation

@rubynguyen1510

@rubynguyen1510 rubynguyen1510 commented Jul 18, 2023

Copy link
Copy Markdown

Feat 4122: Add compressImage function in Python

Checklist:

  • Ask to be assigned to the issue.
  • Implement function compressImage() in Python/ 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 #4122.

Authors: Noah Jacinto, Ngoc Nguyen.

Summary

This pull request creates a function that performs lossless compression on an image by integrating Tinypng and KrakenIO API. The function should receive a request containing a payload and environment variables. The payload should contain a provider and a base64 encoded image, while the variables contain the corresponding api key(s). After sending a request, the function will return a response with the compressed version of the image in base64 encoded format.

Details

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

  • main.py contains functions to validate requests and perform image optimization through the TinyPNG/KrakenIO provider.

  • requirements.txt contains Python packages and dependencies used for our build.

  • secret.py contains API Key Variables for Tinypng and KrakenIO. It includes API_KEY_TINYPNG, API_KEY_KRAKENIO and SECRET_API_KEY_KRAKENIO. These values should be changed to your respective api keys.

  • test_main.py contains unittest for the main.py file with various scenarios like happy paths, value errors, unexpected exceptions etc. test_main.py uses 1kb.png, 1kb_result_encoded_krakenio.txt and 1kb_result_encoded_tinypng.txt inside the test folder.

Testing

More information about setting up the environment, refer toREADME.md.

  • Tinypng

TinyPNG Curl Example (Supports only API_KEY in Environment Variables)

curl http://localhost:3000/ -H "X-Internal-Challenge: secret-key" -H "Content-Type: application/json" -d '{"payload": {"provider": "tinypng", "image": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAA1JREFUGFdj+L+U4T8ABu8CpCYJ1DQAAAAASUVORK5CYII="}, "variables": {"API_KEY": "<YOUR_API_KEY>"}}

TinyPNG response.
image

  • KrakenIO

KrakenIO Curl Example (Supports API_KEY and SECRET_API_KEY in Environment Variables)

curl http://localhost:3000/ -H "X-Internal-Challenge: secret-key" -H "Content-Type: application/json" -d '{"payload": {"provider": "krakenio", "image": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAA1JREFUGFdj+L+U4T8ABu8CpCYJ1DQAAAAASUVORK5CYII="}, "variables": {"API_KEY": "<YOUR_API_KEY>", "SECRET_API_KEY": "<YOUR_SECRET_API_KEY>"}}'

KrakenIO response.
image


Test Results

Provider Before After
TinyPNG image image
KrakenIO image image

@rubynguyen1510 rubynguyen1510 changed the title Feat 4122 compress image python Feat 4122 compressImage python Jul 18, 2023
@Mushmou

Mushmou commented Jul 18, 2023

Copy link
Copy Markdown

@rubynguyen1510 we did it!

@rubynguyen1510

Copy link
Copy Markdown
Author

@Mushmou

@rubynguyen1510

Copy link
Copy Markdown
Author

I made a mistake. Sorry!

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.

2 participants