Hellnar
Hellnar

Reputation: 64793

Python: Grabbing the width and height of image from url

A 3rd party app saves images in such naming format where q85 is the quality, AAxBB means width and height:

62620587b.jpg.122x132_q85.jpg -> 122x132

62620587c.jpg.143x85_q85.jpg -> 143x85

6768113_sa.jpg.122x132_q85.jpg -> 122x132

Toshiba_50-Inch_Side.jpg.150x150_q85.jpg -> 150x150

What is the clever way to split width and height numbers from such string urls?

Upvotes: 0

Views: 132

Answers (2)

Hamoudaq
Hamoudaq

Reputation: 1498

re.findall("[\d]+x[\d]+",variable_string)

but it will produce an duplication because the line 62620587b.jpg.122x132_q85.jpg -> 122x132 contain the AAxBB twice ,,, you can make an method that delete the duplication

Upvotes: 2

alex
alex

Reputation: 1304

Shortest way to do it:

/(\d+)x(\d+)/

What the problem?

Upvotes: 0

Related Questions