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

Added function to find the dominant color of a given image and added formatting markdown files #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Contributing to Ithaca Transit Backend
👍🎉 First off, congrats on getting put on this pod 😂🎉👍

The following is a set of guidelines for contributing to our backend. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.

# Versioning
This is _extremely_ important as handling our backend can get quite messy.

# Making PRs
We want our PRs to be concise but informative. Some pointers as per our PR template:
### Title
Summarize what changes you've made in one sentence. For example: "Exclude staff from the check for follows". For stacked PRs, please indicate clearly in the title where in the stack you are. For example: "[Eatery Refactor][4/5] Converted all files to MVP model."
### Overview
Summarize generally what the purpose of this PR is.
### Changes
Include details of what your changes actually are and how it is intended to work.
### Test Coverage
Describe how you tested this feature: manual testing and/or unit testing. Please include repro steps and/or how to turn the feature on if applicable. In the context of this repo, add a plan for how you intend to test on [integration](https://github.com/cuappdev/integration), with your newly created issue linked.
### Next Steps
If this applies, describe how you plan on addressing future PRs if this is a part of a multi-PR change.
### Related PRs or Issues
If this applies, list related PRs against other branches or repositories.

17 changes: 17 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Overview


## Changes Made


## Test Coverage


## Next Steps


## Related PRs or Issues


## Screenshots
<img src="image url here" width="300"/>
33 changes: 33 additions & 0 deletions src/utils/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import requests
from PIL import Image
from io import BytesIO
from collections import Counter

BASE_URL = "https://dxbhsrqyrr690.cloudfront.net/sidearm.nextgen.sites/cornellbigred.com"

def get_dominant_color(relative_path, white_threshold=200, black_threshold=50):
image_url = f"{BASE_URL}{relative_path}"

response = requests.get(image_url)
image = Image.open(BytesIO(response.content)).convert("RGBA")

image = image.resize((50, 50))
image = image.quantize(colors=5).convert("RGBA")

Choose a reason for hiding this comment

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

Did quantizing to 5 colors work the best? I'm wondering if quantizing to more colors might work better but this seems fine as it is right now

pixels = image.getdata()

filtered_pixels = [
pixel for pixel in pixels
if not (pixel[0] > white_threshold and pixel[1] > white_threshold and pixel[2] > white_threshold) and
not (pixel[0] < black_threshold and pixel[1] < black_threshold and pixel[2] < black_threshold)
]

if filtered_pixels:
pixel_count = Counter(filtered_pixels)
dominant_color = pixel_count.most_common(1)[0][0]
else:
dominant_color = (0, 0, 0)

Choose a reason for hiding this comment

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

if there is no dominant_color found, it will return a RGB value, but if there is one found, it will return a RGBA value, which might cause issues


return dominant_color

dominant_color = get_dominant_color('/images/logos/Princeton_Tigers.png?width=80&height=80&mode=max')
print(f"Dominant color: {dominant_color}")

Choose a reason for hiding this comment

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

remove test