Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1054913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:28:51+00:00 2026-05-16T17:28:51+00:00

I am using simplehtmldom class to get all images from a website, i am

  • 0

I am using simplehtmldom class to get all images from a website,

i am trying to get width and height of image returned by simplehtmldom,

what i am trying to accomplish here is, if a image width less than 50px, i don’t want the image to be displayed.

I tried getimagesize(), however its often keep on timeout i think due to amount of images.

Any idea?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:28:52+00:00Added an answer on May 16, 2026 at 5:28 pm

    Using getimagesize() is very slow, especially if you’re scraping a site and get many images. PHP has to download the entirety of each image BEFORE it can pass the data to getimagesize(), so if you’re working on (for instance) a large photo gallery, you could be downloading many megabytes per image.

    There’s a few things you can do to speed up the process:

    1. check the height/width attributes of the <img> tag and only grab images where either’s larger than 50. They might not necessarily be accurate, as the web page creator could be stretching or shrinking the image, but it would save you from downloading accurately sized small images.

    2. Instead of fetching the images directly with getimagesize() you could try to fetch only the first couple hundred bytes of each, which will contain the image header information. For GIF/JPEG images, the height/width will be very near the beginning on the file, so you’d save on file transfer overhead.

    3. Increase your script’s execution time. Fetching all the images will naturally be a fairly slow process, and you’ll most likely run up against PHP’s max_execution_time

    comment followup:

    Well, if there’s no height/width, then you can jump straight to fetching the image (or first bit of the image) and extracting height/width directly. Checking the height/width in the tag is just to save you the trouble of having to fetch the image in the first place.

    As for extracting the height/width from the HTML, it’s just a matter of using ->getAttribute('width') and ->getAttribute('height') calls once you’ve found an <img> tag with the SimpleHTMLDOM. Something like this:

    $dom = file_get_html('http://example.com/somepage.html');
    $images = $dom->find('img');
    
    foreach($images as $img) {
        $h = $img->getAttribute('height');
        $w = $img->getAttribute('width');
    
        if (isnull($h) || (isnull($w)) {
           // height and/or width not available in tag, so fetch image and get size that way
           $h = ...
           $w = ...
        }
    
        if (($h >= 50) && ($w >= 50)) {
            // image is bigger than 50x50, so display it...
        }
    }
    

    This probably won’t work if you cut/paste it, just doing off the top of my head, but it should be enough to get you started.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to retrieve images from any site that has images I'm using simplehtmldom
I am trying to write a web scraper using simplehtmldom. I want to get
Using the Redis info command, I am able to get all the stats of
Hi guys I'm using this wonderful class here to do a bit of code
I'm using: http://simplehtmldom.sourceforge.net/ and noticed that in the examples, and trying to scrape certain
I want to get the title of an article from this page using regex
I'm trying to get the content of a webpage that require authentication using PHP.
I'm trying to select either a class or an id using PHP Simple HTML
Using JQuery, how do I select all elements with class x within an element
My php script uses php simplehtmldom to parse html and get all the links

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.