79381427

Date: 2025-01-23 14:18:49
Score: 0.5
Natty:
Report link

After the helpful advice of the above, here is what I was able to come up with:

import numpy as np
import matplotlib.pyplot as plt
from PIL import Image

img = Image.open('level.jpg') #open the image that you want to zoom into
img_save = img
w, h = img.size

distance = 2 # in this case this image will be zoomed in by 10
distance2 = 1

zm=distance/distance2 #should be bigger than 1 to make it work

wn = w // zm # this is the *new size* of the image after being zoomed in
hn = h // zm

widthStart  = (w - wn) // 2
heightStart = (h - hn) // 2
widthEnd    = widthStart + wn
heightEnd   = heightStart + hn

img = img.crop((widthStart, heightStart, widthEnd, heightEnd))
img = img.resize((w, h), Image.LANCZOS)

plt.imshow(np.array(img))
plt.show()
plt.imshow(np.array(img_save))
plt.show()
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: CakeMaster