|
|
import requests |
|
|
import os |
|
|
|
|
|
url = "http://localhost:8000/image/convert" |
|
|
input_dir = "image/input" |
|
|
file_path = os.path.join(input_dir, "test_quality.jpg") |
|
|
output_dir = "image/output" |
|
|
|
|
|
|
|
|
os.makedirs(input_dir, exist_ok=True) |
|
|
os.makedirs(output_dir, exist_ok=True) |
|
|
|
|
|
|
|
|
from PIL import Image |
|
|
Image.new('RGB', (100, 100), color='red').save(file_path) |
|
|
|
|
|
|
|
|
data = { |
|
|
"id": "test_quality.jpg", |
|
|
"to_format": "jpg", |
|
|
"quality": 50, |
|
|
"scale": 0.5 |
|
|
} |
|
|
|
|
|
try: |
|
|
response = requests.post(url, data=data) |
|
|
if response.status_code == 200: |
|
|
result = response.json() |
|
|
print(f"Success: {result}") |
|
|
|
|
|
|
|
|
output_file = os.path.join(output_dir, result['new_filename']) |
|
|
if os.path.exists(output_file): |
|
|
print(f"Output file created: {output_file}") |
|
|
print(f"Output file size: {os.path.getsize(output_file)} bytes") |
|
|
else: |
|
|
print("Error: Output file not found") |
|
|
else: |
|
|
print(f"Failed: {response.status_code} - {response.text}") |
|
|
except Exception as e: |
|
|
print(f"Error: {e}") |
|
|
|