GAE images.resize 使用固定比例裁剪
我需要从各种尺寸调整大小并裁剪为正好 60x80px 长宽比。就在我放入数据存储之前。任何人都已经得到了 这个问题解决了。
目前我已经成功地将其转换为精确的高度(80px) 具有各种宽度,当我尝试显示它时看起来不太好 一个清单。例如杰卡鲁塞尔。
我的 db.put 代码如下所示:
if users.get_current_user():
personal.personal_id = int(self.request.get('personal_id'))
personal.name = self.request.get('name')
personal.latitude = self.request.get('latitude')
personal.info = self.request.get('info')
photo = images.resize(self.request.get('img'), 0, 80)
personal.photo = db.Blob(photo)
personal.lc_id = int(self.request.get('lc_id'))
personal.put()
self.redirect('/admin/personal')
else:
self.response.out.write('I\'m sorry, you don\'t have permission to add this LP Personal Data.')
当我们在谷歌上上传头像时,我只想做类似的结果 谈话/谷歌聊天。
有人解决这个问题了吗?
谢谢
I need to resize and crop to exactly 60x80px from various size and
aspect ratio. Just before i put into Datastore. Anyone already got
this issue resolved.
Currently i already succed to just transform it to exact height (80px)
with various width which nott look so good when i try to display it on
a list. e.g jcaroussel.
My db.put code is like bellow:
if users.get_current_user():
personal.personal_id = int(self.request.get('personal_id'))
personal.name = self.request.get('name')
personal.latitude = self.request.get('latitude')
personal.info = self.request.get('info')
photo = images.resize(self.request.get('img'), 0, 80)
personal.photo = db.Blob(photo)
personal.lc_id = int(self.request.get('lc_id'))
personal.put()
self.redirect('/admin/personal')
else:
self.response.out.write('I\'m sorry, you don\'t have permission to add this LP Personal Data.')
I just want to do similar result when we upload our avatar on google
talk/google chat.
Anyone solved this?
Thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将图片高度调整为 80 像素后,您必须使用 此处。例如:
在我的示例中,它裁剪到图像的中心。
它假设调整后的图像宽度至少为 60 像素,但显然您必须添加一些检查来确认这一点,因为用户可能无法上传正确尺寸的图像。
After your resize your image down to 80 pixels in height, you would have to use the
crop
function as defined here. For example:In my example it crops to the center of the image.
It assumes that the resized image is at least 60 pixels wide, but obviously you would have to add some checks to confirm this, because a user might not upload an image in the right size.
我使用了其他东西:
中:
宽度:60px;高度:80像素;溢出:隐藏;
这样它会在您的列表中很好地显示,但您仍然可以在用户的个人资料页面上显示完整的调整大小的图片(看着您的代码,我想这就是您想要做的,对吧?)
I used something else:
<div>
that has the following CSS:width: 60px; height: 80px; overflow: hidden;
That way it will show nicely in your list, but you can still display the complete resized picture on your user's profile page (looking at you code I imagine that's what you are trying to do, right?)