@@ -377,87 +377,6 @@ public function find($selector, $nth = null)
377377 return $ nodes ;
378378 }
379379
380- /**
381- * Function to try a few tricks to determine the displayed size of an img on the page.
382- * NOTE: This will ONLY work on an IMG tag. Returns FALSE on all other tag types.
383- *
384- * Future enhancement:
385- * Look in the tag to see if there is a class or id specified that has a height or width attribute to it.
386- *
387- * Far future enhancement
388- * Look at all the parent tags of this image to see if they specify a class or id that has an img selector that specifies a height or width
389- * Note that in this case, the class or id will have the img sub-selector for it to apply to the image.
390- *
391- * ridiculously far future development
392- * If the class or id is specified in a SEPARATE css file that's not on the page, go get it and do what we were just doing for the ones on the page.
393- *
394- * @author John Schlick
395- * @return array an array containing the 'height' and 'width' of the image on the page or -1 if we can't figure it out.
396- */
397- public function get_display_size ()
398- {
399- $ width = -1 ;
400- $ height = -1 ;
401-
402- if ($ this ->tag ->name () != 'img ' ) {
403- return false ;
404- }
405-
406- // See if there is a height or width attribute in the tag itself.
407- if ( ! is_null ($ this ->tag ->getAttribute ('width ' ))) {
408- $ width = $ this ->tag ->getAttribute ('width ' );
409- }
410-
411- if ( ! is_null ($ this ->tag ->getAttribute ('height ' ))) {
412- $ height = $ this ->tag ->getAttribute ('height ' );
413- }
414-
415- // Now look for an inline style.
416- if ( ! is_null ($ this ->tag ->getAttribute ('style ' ))) {
417- // Thanks to user 'gnarf' from stackoverflow for this regular expression.
418- $ attributes = [];
419- preg_match_all ("/([\w-]+)\s*:\s*([^;]+)\s*;?/ " , $ this ->tag ->getAttribute ('style ' ), $ matches ,
420- PREG_SET_ORDER );
421- foreach ($ matches as $ match ) {
422- $ attributes [$ match [1 ]] = $ match [2 ];
423- }
424-
425- $ width = $ this ->getLength ($ attributes , $ width , 'width ' );
426- $ height = $ this ->getLength ($ attributes , $ width , 'height ' );
427- }
428-
429- $ result = [
430- 'height ' => $ height ,
431- 'width ' => $ width ,
432- ];
433-
434- return $ result ;
435- }
436-
437- /**
438- * If there is a length in the style attributes use it.
439- *
440- * @param array $attributes
441- * @param int $length
442- * @param string $key
443- * @return int
444- */
445- protected function getLength (array $ attributes , $ length , $ key )
446- {
447- if (isset ($ attributes [$ key ]) && $ length == -1 ) {
448- // check that the last two characters are px (pixels)
449- if (strtolower (substr ($ attributes [$ key ], -2 )) == 'px ' ) {
450- $ proposed_length = substr ($ attributes [$ key ], 0 , -2 );
451- // Now make sure that it's an integer and not something stupid.
452- if (filter_var ($ proposed_length , FILTER_VALIDATE_INT )) {
453- $ length = $ proposed_length ;
454- }
455- }
456- }
457-
458- return $ length ;
459- }
460-
461380 /**
462381 * Gets the inner html of this node.
463382 *
0 commit comments