1

I am new to web-scraping ,I want a program that download images using bs4 and urllib3 but I want to download resized image ,I have previously used the following code

urllib.request.urlretrieve("https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE4wyTq?ver=c8e5&quot","image.jpg")

but this downloads image in it's real size I want to download this image with different height and weight What can I do?

Saksham Kushwaha
  • 274
  • 1
  • 18
  • 1
    Unless the CMS / web application that manages this image online offers some query parameters you can add (along the lines of `&width=400&height=300`) to generate a URL which gets you directly what you want, you'll need to download the full image and resize it locally, then throw away the downloaded larger file. Or possibly you could find a web service that can resize it on the fly, but that gets into "asking for opinions" territory. – Grismar Sep 07 '20 at 05:34
  • You need to use another library for this, like PIL, and process the image after you download it in its original size. – fpietka Sep 07 '20 at 05:35
  • @fpietka how can I do that can you explain with code – Saksham Kushwaha Sep 07 '20 at 05:36
  • you could follow the example there: https://stackoverflow.com/a/37631799/1481213 – fpietka Sep 07 '20 at 05:39

1 Answers1

1

Try this:

from skimage import io
import cv2
width,height = 'some_w', 'some_h'
req = io.imread("https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE4wyTq?ver=c8e5&quot")
cv2.imwrite("image.jpg", cv2.resize(req, (width,height)))
dimay
  • 2,768
  • 1
  • 13
  • 22