ChatGPT (model unspecified)· OpenAI
ShareLM (browser-extension contributions)
image size: code
- User
image size: code
- Assistant
Could you clarify what exactly you mean by “image size: code”? Do you want:
A code snippet to get the size (width & height) of an image?
Or to resize an image to a particular size using code?
Or just an explanation of how image size is represented in code (pixels, resolution, etc.)?
Here are quick examples for both Python cases:
- Get Image Size (using Pillow): pythonCopyEditfrom PIL import Image
Open image
img = Image.open("example.png")
Get size
width, height = img.size print(f"Width: {width}, Height: {height}")
- Resize Image: pythonCopyEditfrom PIL import Image
img = Image.open("example.png")
Resize to 256x256
resized_img = img.resize((256, 256))
Save resized image
resized_img.save("resized.png")
👉 Do you want me to give you code for checking size, resizing, or something else (like compressing, changing DPI, etc.)?