79552225

Date: 2025-04-03 07:10:32
Score: 1
Natty:
Report link

from PIL import Image

# បើករូបភាព

image = Image.open("your_image.jpg")

# កំណត់ទំហំ (4x6 cm) (ម្យ៉ាងត្រូវដឹង DPI)

dpi = 300 # ឧ. 300 DPI

width_px = int(4 * dpi / 2.54) # 4 cm to pixels

height_px = int(6 * dpi / 2.54) # 6 cm to pixels

# កាត់ (crop) ចេញពីកណ្ដាល

center_x, center_y = image.width // 2, image.height // 2

left = center_x - width_px // 2

top = center_y - height_px // 2

right = center_x + width_px // 2

bottom = center_y + height_px // 2

cropped_image = image.crop((left, top, right, bottom))

# រក្សាទុករូបដែលបានកាត់

cropped_image.save("cropped_image.jpg", dpi=(dpi, dpi))

print("✅ រូបត្រូវបាន crop ទំហំ 4x6 cm ដោយជោគជ័យ!")

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: moeun lihou