I have a django based website in which I have created profiles of people working in the organisation. Since this is a redesign effort, I used the already existing profile pictures. The size of current profile image style is 170x190px. Since the images already exist and are of different sizes, I want to crop them to the size specified above. But how do I decide from which side I have to crop?
我有一个django网站,我在这个网站上创建了在该组织工作的人的简介。由于这是一项重新设计工作,我使用了已经存在的概要图片。当前配置文件图像样式的大小是170x190px。由于图像已经存在,并且大小不同,所以我想将它们裁剪到上面指定的大小。但是我如何决定我要从哪一边收割呢?
Currently, I have applied style of 170by190 to all the images while displaying in profiles, but most of them look distorted as the aspect ratios do not match.
目前,我在配置文件中显示的所有图片都采用了170by190的样式,但由于纵横比不匹配,大部分都显得变形了。
I have tried PIL thumbnail function but it does not fit the need.
我尝试过PIL缩略图功能,但是不符合需要。
Please suggest a solution.
请建议一个解决方案。
2 个解决方案
#1
1
Well, you have to resize pictures, but images ratio create huge impact on final result. As images have some ratio, and you cannot simply resize them to 170px190px without prior adjusting of their ratio, so you have to update( not crop them!) images before resizing them to get best possible output, it can be done in next ways:
你必须调整图片的大小,但是图片比例会对最终结果产生巨大的影响。由于图像有一定的比例,你不能简单地将它们调整为170px190px,而无需事先调整它们的比例,因此在调整它们以获得最佳输出之前,必须更新(而不是裁剪它们!)图像,可以在下一种方法中完成:
- Crop them manually to desired ratio (17:19). (take a while if you have plenty of images)
- 按照期望的比例手工裁剪(17:19)。(如果你有足够多的图片的话,花点时间)
- Create script which add padding to that images if image ratio is close to required, all images which ratio is far away from desired mark as 'human cropping required' and work with their ratio later by own (semi-manual, so still may be really time consuming)
- 创建脚本,如果图像的比例接近要求,那么就为该图像添加填充,所有的图像的比例都与期望的标记相差甚远,作为“需要人工裁剪”,并在以后自行处理它们的比例(半手工操作,因此仍然可能非常耗时)
- Spend some time and write face recognation function, then process images with that function and find faces, then crop them from origin image, but before: add padding to achieve desired radio (17:19) at top and bottom of face. (recommended)
- 花些时间编写face recognation函数,然后用这个函数处理图像并找到人脸,然后从原始图像中裁剪出来,但在此之前:在人脸的顶部和底部添加填充以实现所需的广播(17:19)。(推荐)
Some links which may be use full for you:
以下是一些可能对你有用的链接:
- Face Recognition With Python, in Under 25 Lines of Code
- 用Python来识别,在25行代码中。
- facereclib module, they probably are able to help you.
- facereclib模块,它们可能可以帮助您。
- Image Manipulation, The Hitchhiker’s Guide
- 图像处理,搭便车者指南
Good luck !
祝你好运!
#2
#1
1
Well, you have to resize pictures, but images ratio create huge impact on final result. As images have some ratio, and you cannot simply resize them to 170px190px without prior adjusting of their ratio, so you have to update( not crop them!) images before resizing them to get best possible output, it can be done in next ways:
你必须调整图片的大小,但是图片比例会对最终结果产生巨大的影响。由于图像有一定的比例,你不能简单地将它们调整为170px190px,而无需事先调整它们的比例,因此在调整它们以获得最佳输出之前,必须更新(而不是裁剪它们!)图像,可以在下一种方法中完成:
- Crop them manually to desired ratio (17:19). (take a while if you have plenty of images)
- 按照期望的比例手工裁剪(17:19)。(如果你有足够多的图片的话,花点时间)
- Create script which add padding to that images if image ratio is close to required, all images which ratio is far away from desired mark as 'human cropping required' and work with their ratio later by own (semi-manual, so still may be really time consuming)
- 创建脚本,如果图像的比例接近要求,那么就为该图像添加填充,所有的图像的比例都与期望的标记相差甚远,作为“需要人工裁剪”,并在以后自行处理它们的比例(半手工操作,因此仍然可能非常耗时)
- Spend some time and write face recognation function, then process images with that function and find faces, then crop them from origin image, but before: add padding to achieve desired radio (17:19) at top and bottom of face. (recommended)
- 花些时间编写face recognation函数,然后用这个函数处理图像并找到人脸,然后从原始图像中裁剪出来,但在此之前:在人脸的顶部和底部添加填充以实现所需的广播(17:19)。(推荐)
Some links which may be use full for you:
以下是一些可能对你有用的链接:
- Face Recognition With Python, in Under 25 Lines of Code
- 用Python来识别,在25行代码中。
- facereclib module, they probably are able to help you.
- facereclib模块,它们可能可以帮助您。
- Image Manipulation, The Hitchhiker’s Guide
- 图像处理,搭便车者指南
Good luck !
祝你好运!