在Web应用程序中,使用img标记的宽度和高度属性是良好的实践--这允许浏览器更快地呈现页面。
如果我有图像的宽度和高度以及ImageMagick格式字符串(即“300>”),如何获取该图像调整大小后的大小?我希望ImageMagick有一些钩子/函数可以让我访问此信息。
我只想知道新的尺寸大小,而不想调整大小或将图像加载到内存中。
本质上,我需要以下函数:
def get_image_size(width, height, format_string) # ... magic here return [new_width, new_height] end
width, height = get_image_size(300, 400, '235x235!') # would return 235 and 235
width, height = get_image_size(300, 400, '700x700>') # would return 300 and 400
width, height = get_image_size(300, 400, '100x100') # would return 75 and 100
如果我有图像的宽度和高度以及ImageMagick格式字符串(即“300>”),如何获取该图像调整大小后的大小?我希望ImageMagick有一些钩子/函数可以让我访问此信息。
我只想知道新的尺寸大小,而不想调整大小或将图像加载到内存中。
本质上,我需要以下函数:
def get_image_size(width, height, format_string) # ... magic here return [new_width, new_height] end
width, height = get_image_size(300, 400, '235x235!') # would return 235 and 235
width, height = get_image_size(300, 400, '700x700>') # would return 300 and 400
width, height = get_image_size(300, 400, '100x100') # would return 75 and 100