Skip to content

Commit

Permalink
Merge pull request #101 from msmthng/master
Browse files Browse the repository at this point in the history
  • Loading branch information
jneilliii authored Feb 20, 2023
2 parents cf901b0 + 9bd0798 commit 994c0eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v3
- uses: actions/stale@v7
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue has been automatically marked as stale because it has not had activity in 14 days. It will be closed if no further activity occurs in 7 days'
Expand Down
15 changes: 14 additions & 1 deletion octoprint_prusaslicerthumbnails/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,21 @@ def _extract_flashprint_thumbnail(self, gcode_encoded_images):
encoded_image = gcode_encoded_images[0]

image = Image.open(io.BytesIO(encoded_image)).resize((160,120))
rgba = image.convert("RGBA")
pixels = rgba.getdata()
newData = []

alphamaxvalue = 35
for pixel in pixels:
if pixel[0] >= 0 and pixel[0] <= alphamaxvalue and pixel[1] >= 0 and pixel[1] <= alphamaxvalue and pixel[2] >= 0 and pixel[2] <= alphamaxvalue : # finding black colour by its RGB value
newData.append((255, 255, 255, 0)) # storing a transparent value when we find a black/dark colour
else:
newData.append(pixel) # other colours remain unchanged

rgba.putdata(newData)

with io.BytesIO() as png_bytes:
image.save(png_bytes, "PNG")
rgba.save(png_bytes, "PNG")
png_bytes_string = png_bytes.getvalue()
return png_bytes_string

Expand Down

0 comments on commit 994c0eb

Please sign in to comment.