如何在 python 中使用 pythonMagick 将图像适合固定大小的框
try:
original = PythonMagick.Blob(data)
image = PythonMagick.Image(original)
except Exception as e:
raise errors.UnknownFileFormat()
medium = PythonMagick.Blob()
small = PythonMagick.Blob()
large = PythonMagick.Blob()
largesize = "128X128"
mediumsize = "64X64"
smallsize = "48X48"
image.scale(largesize)
image.write(large)
image.scale(mediumsize)
image.write(medium)
image.scale(smallsize)
image.write(small)
现在,我需要创建每个尺寸的基本图像并将这些图像叠加在其上。这样,当我在具有固定宽度和高度的 img 标签中显示显示时,浏览器不会拉伸它们。缺乏文档让我很恼火。
try:
original = PythonMagick.Blob(data)
image = PythonMagick.Image(original)
except Exception as e:
raise errors.UnknownFileFormat()
medium = PythonMagick.Blob()
small = PythonMagick.Blob()
large = PythonMagick.Blob()
largesize = "128X128"
mediumsize = "64X64"
smallsize = "48X48"
image.scale(largesize)
image.write(large)
image.scale(mediumsize)
image.write(medium)
image.scale(smallsize)
image.write(small)
Now, what I need is to create a base image of each of the sizes and overlay these images on top of it. So that when I show display in an img tag with fixed width and height, the browser does not stretch them. The lack of documentation is aggravating me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能可以通过
background-size:cover
或background-size:contain
和background-position:... 来实现您在 CSS 中尝试执行的操作;
。如果尝试做其他事情可能会更复杂。You can probably achieve what you are trying to do in CSS by
background-size:cover
orbackground-size:contain
andbackground-position:...;
. May be more complicated if trying to do other things.