Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save blopa/cd83c38cf2dc61476ee8d635c27c6a75 to your computer and use it in GitHub Desktop.
Save blopa/cd83c38cf2dc61476ee8d635c27c6a75 to your computer and use it in GitHub Desktop.
Code for post "Transforming manga pages for lazy western readers"
def create_image_with_inverted_text_placement(base_image, data):
width, height = base_image.size
new_image = Image.new('RGBA', (width, height), (255, 255, 255, 0))
data = json.loads(data)
for index, item in enumerate(data):
x, y = item['location']
box_width, box_height = item['width'], item['height']
if box_width <= 0 or box_height <= 0:
continue
new_x = width - x - box_width
cropped_image = base_image.crop((x, y, x + box_width, y + box_height))
cropped_image = cropped_image.convert('RGBA')
new_image.paste(cropped_image, (new_x, y), cropped_image)
return new_image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment