python - How to resize only image width using scrapy? -


using scrapy can resize image , keep aspect ratio. http://doc.scrapy.org/en/latest/topics/images.html#std:setting-images_thumbs

images_thumbs = {     'small': (50, 50),     'big': (270, 270),  } 

what want re sizing image width , keeping image height is. know how ?

note: i'm using scrapy upload images amazon s3, don't have option of resizing them locally.

you create own images pipeline. in item_completed method, can open downloaded images , resize them using pil. scrapy uses pil imaging pipelines.

here tentative example. (i don't use scrapy.)

from scrapy.contrib.pipeline.images import imagespipeline scrapy.exceptions import dropitem scrapy.http import request  pil import image  class myimagespipeline(imagespipeline):      def get_media_requests(self, item, info):         image_url in item['image_urls']:             yield request(image_url)      def item_completed(self, results, item, info):         result, image_info in results:             if result:                 path = image_info['path']                 img = image.open(path)                 # here resizing - method overwrites                 # original image need create copy if want keep                 # original.                 img = img.resize((100, 72))                 img.save(path)         return item 

you can see scrapy in default image pipeline: https://github.com/scrapy/scrapy/blob/master/scrapy/contrib/pipeline/images.py#l283. , below line 300 can read default implementations these 2 methods.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -