gpt-4-0125-preview· openai
Suzhen/CodeChat
generate 1 color image with random resolution from 50x50 to 150x150 pixels using python
- User
generate 1 color image with random resolution from 50x50 to 150x150 pixels using python
- Assistant
To generate a color image with random resolution ranging from 50x50 to 150x150 pixels, you can use the Python Imaging Library (PIL), which is now part of the Pillow library. If you haven't already, you'll need to install Pillow using pip:
pip install PillowHere is a script that creates a color image with a random resolution within the specified range:
from PIL import Image import random # Random resolution between 50x50 and 150x150 width = random.randint(50, 150) height = random.randint(50, 150) # Create a new image with random RGB values image = Image.new('RGB', (width, height), (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))) # Optionally, to make the image more interesting, you can fill it with random colors instead of a single color pixels = image.load() for x in range(width): for y in range(height): pixels[x, y] = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) # Save the image image.save('random_image.png') print(f'Image saved with a size of {width}x{height} pixels.')