“Python RESATIVE Ratio de aspecto de mantenimiento de la imagen” Código de respuesta

C# RESEA CON LA IMAGÍA DE LA IMAGEN RELACIÓN DE ASPECTIVO

using System.Drawing;
public static Size ResizeKeepAspect(this Size src, int maxWidth, int maxHeight, bool enlarge = false)
{
    maxWidth = enlarge ? maxWidth : Math.Min(maxWidth, src.Width);
    maxHeight = enlarge ? maxHeight : Math.Min(maxHeight, src.Height);

    decimal rnd = Math.Min(maxWidth / (decimal)src.Width, maxHeight / (decimal)src.Height);
    return new Size((int)Math.Round(src.Width * rnd), (int)Math.Round(src.Height * rnd));
}
Mingles444

Mantenga la relación de aspecto de la imagen CSS

img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
}
Mobile Star

Python RESATIVE Ratio de aspecto de mantenimiento de la imagen

def resize_with_pad(im, target_width, target_height):
    '''
    Resize PIL image keeping ratio and using white background.
    '''
    target_ratio = target_height / target_width
    im_ratio = im.height / im.width
    if target_ratio > im_ratio:
        # It must be fixed by width
        resize_width = target_width
        resize_height = round(resize_width * im_ratio)
    else:
        # Fixed by height
        resize_height = target_height
        resize_width = round(resize_height / im_ratio)

    image_resize = im.resize((resize_width, resize_height), Image.ANTIALIAS)
    background = Image.new('RGBA', (target_width, target_height), (255, 255, 255, 255))
    offset = (round((target_width - resize_width) / 2), round((target_height - resize_height) / 2))
    background.paste(image_resize, offset)
    return background.convert('RGB')
Yellowed Yak

Respuestas similares a “Python RESATIVE Ratio de aspecto de mantenimiento de la imagen”

Preguntas similares a “Python RESATIVE Ratio de aspecto de mantenimiento de la imagen”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código