Изображение изменяет размер в Grails

Если вы ожидаете JSON-объект, установите contentType и запросите заголовок, как указано ниже.

и вы можете попробовать jQuery.isEmptyObject (response), чтобы убедиться, что объект пуст или нет.

$.ajax({
        url:  url, 
        dataType: 'json',
        type: method type,
        data : data,
        contentType: "application/json",
        beforeSend: function (e) {
            e.setRequestHeader('Accept', 'application/json; charset=utf-8')
        },
        success: function (response) {
            if(!jQuery.isEmptyObject(response)){
                //logic
            }else{
                //No object recived from backend
            }
        },
        error: function () {
            console.log ("Failed!");
        }
    });
13
задан Wasim 18 October 2012 в 15:58
поделиться

2 ответа

import java.awt.Image as AWTImage 
import java.awt.image.BufferedImage      
import javax.swing.ImageIcon 
import javax.imageio.ImageIO as IIO  
import java.awt.Graphics2D


static resize = { bytes, out, maxW, maxH -> 
    AWTImage ai = new ImageIcon(bytes).image 
    int width = ai.getWidth( null ) 
    int height = ai.getHeight( null )

    def limits = 300..2000 
    assert limits.contains( width ) && limits.contains( height ) : 'Picture is either too small or too big!'

    float aspectRatio = width / height float requiredAspectRatio = maxW / maxH

    int dstW = 0 
    int dstH = 0 
    if (requiredAspectRatio < aspectRatio) { 
        dstW = maxW dstH = Math.round( maxW / aspectRatio) 
    } else { 
        dstH = maxH dstW = Math.round(maxH * aspectRatio) 
    }

    BufferedImage bi = new BufferedImage(dstW, dstH,   BufferedImage.TYPE_INT_RGB)            
    Graphics2D g2d = bi.createGraphics() g2d.drawImage(ai, 0, 0, dstW, dstH, null, null) 

    IIO.write( bi, 'JPEG', out )
} 
8
ответ дан 1 December 2019 в 21:53
поделиться

Используйте плагин ImageTool. https://grails.org/plugin/image-tools P.S. Доступный только для чаш Грааля v2.

2
ответ дан 1 December 2019 в 21:53
поделиться
Другие вопросы по тегам:

Похожие вопросы: