App Engine 图像调整大小而不保持纵横比?
当我使用应用程序引擎对图像调用调整大小时,它们会保持其纵横比 - 我最终不会得到我要求的大小。
我正在尝试从方形像素源制作矩形像素 NTSC 图像,所以我不希望出现这种行为,
我想拍摄 720x540 的图像并将其大小调整为 720x480,但当要求调整大小时,我实际上最终得到的是640x480 的图像。
有什么办法解决这个问题吗?
When I call resize on images using app engine, they maintain their aspect ratio - I don't end up with the size I ask for.
I'm trying to make rectangular pixel NTSC images from square pixel sources, so I don't want this behaviour
I want to take an image that is 720x540 and resize it to 720x480 but what I actually end up when ask for the resize is an image that is 640x480.
Is there any way round this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
唉,虽然 PIL 本身就可以做到这一点,但这并不是 App Engine 非常简单的
images
功能正在使用(您可能会对 SDK 确实使用 PIL 在您的开发计算机上实现该功能的 API 感到困惑)——特别是,resize
始终 确实尊重纵横比。您获得更高功能的机会取决于在应用程序引擎的问题跟踪器上请求它,并希望许多开发人员有这种需求!Alas, while PIL per se could do it, that's not what App Engine's very simple
images
functionality is using (you may be confused by the fact that the SDK is indeed using PIL to implement that functionality's API on your development machine) -- in particular,resize
always does respect the aspect ratio. Your chance to get higher functionality depends on asking for it on app engine's issue tracker, and hoping that many developers have that need!您是否给调整大小方法同时指定了宽度和高度?
http://code.google.com/appengine/docs/python/图片/functions.html
Are you giving the resize method both a width and a height?
http://code.google.com/appengine/docs/python/images/functions.html
Adam McGrath 编写了一个很棒的重新缩放函数,可以将图像裁剪为特定的宽度和高度在他的回答中。
Adam McGrath wrote a great rescale function that crops an image to a specific width and height in his answer here.
为什么不使用
crop
函数?将 720x540 图像转换为 720x480 图像的正确参数是(假设您想要中心裁剪):
crop 函数将其参数视为图像宽度或高度的比例,指定为从 0.0 到 1.0 的浮点值。
Why not use the
crop
function?The correct arguments to transform a 720x540 to a 720x480 image would be (presuming you want a center crop):
The
crop
function takes its arguments as a proportion of the image width or height, specified as a float value from 0.0 to 1.0.