Skip to content

validate if a URL is an image #13

@jabbalaci

Description

@jabbalaci

I have a feature request: validate a URL if it's an image or not.

Rationale: I'm writing a scraper that extracts all links. From this list I want to filter out just the image links. I think it could be done simply by analyzing the URL string: if it contains .jpg or .png or .gif then it's an image.

Edit: here is my current solution

IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'gif']    # can be extended

def is_image(path):
    """
    Path can be a URL or a local file. Decide if it's an image or not.
    """
    path = path.lower()
    for x in IMAGE_EXTENSIONS:
        if x in path:
            return True
    #
    return False

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementIssue/PR: A new featureoutdatedIssue/PR: Open for more than 3 months

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions