Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fetch image size and image resolution from HTML content loaded from UIWebview in Swift? #61

Closed
purvimehta16 opened this issue Mar 7, 2018 · 3 comments

Comments

@purvimehta16
Copy link

Using 'SwiftSoup' SDK to parse HTMl content from UIWebView. I want the image size and resolution for each and every images fetched from HTML content. How to get the image size and resolution from HTML content received from SwiftSoup?

@scinfu
Copy link
Owner

scinfu commented Mar 7, 2018

Hi use CSS Selector to find your elements and select your attribute

func testIMGAttribute()throws {
        let h = "<img src=\"img_girl.jpg\" alt=\"Girl in a jacket\" width=\"500\" height=\"600\">"
        let doc = try SwiftSoup.parse(h)
        let imgs: Elements = try doc.select("img[src]")
        for img in imgs {
            try print(img.attr("width"))
        }
    }

other example

func testSRC()throws {
        let h = "<img src=\"img_girl.jpg\" alt=\"Girl in a jacket\" style=\"width:500px;height:600px;\">"
        let doc = try SwiftSoup.parse(h)
        let imgs: Elements = try doc.select("img[src]")
        for img in imgs {
            try print(img.attr("style"))
        }
    }

@purvimehta16
Copy link
Author

Hi, with above lines of code not able to get image size of all the images fetched from Weburl only getting one or two images size.

@0xTim
Copy link
Contributor

0xTim commented Mar 9, 2018

@purvimehta16 it's quite possible that the image size won't be in the HTML/CSS - you'll need to loop through all of the image tags, download them manually and see how big they are

@scinfu scinfu closed this as completed Mar 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants