File size: 784 Bytes
7f09351
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9d3a36f
7f09351
 
 
 
 
 
 
 
9d3a36f
 
7f09351
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import gradio as gr
from PIL import Image
import io
import numpy as np
import tempfile

def muda_dpi(input_image, dpi):
    dpi_tuple = (dpi, dpi)
    
    image = Image.fromarray(input_image.astype('uint8'), 'RGB')
    
    temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.png')
    image.save(temp_file, format='PNG', dpi=dpi_tuple)
    temp_file.close()  
    
    return temp_file.name

# Configurar a interface Gradio
iface = gr.Interface(
    fn=muda_dpi,
    inputs=[
        gr.Image(label="Upload"),
        gr.Number(label="Ajusta DPI", value=300)
    ],
    outputs=gr.File(label="Download"),
    title="Conversor DPI",
    description="Faça o upload da imagem (.jpg, .png), ajuste o DPI e submeta",
    examples=["example1.jpg"]
)

iface.launch(debug=True)