WordPress.org

Forums

WP Mobile Detector
[resolved] Small Images Enlarged on Mobile (2 posts)

  1. bitlost
    Member
    Posted 2 years ago #

    I found that the code which makes sure to shrink images, doesn't check the size of images before it resizes. So when I have a small image on the page that is already less than the maximum image width. It gets resized to a larger image, making the page look incorrect.

    I simply added a check which looked if the image was already smaller than max width and if so ignores the image.

    Here is the code before...

    /*
    Filter content for an advanced mobile device
    */
    function websitez_filter_advanced_page($html){
    	if (class_exists('DOMDocument')) {
    		try{
    			//Resize the images on the page
    			$dom = new DOMDocument();
    			$dom->loadHTML($html);
    
    			// grab all the on the page and make sure they are the right size
    			$xpath = new DOMXPath($dom);
    			$imgs = $xpath->evaluate("/html/body//img");
    
    			for ($i = 0; $i < $imgs->length; $i++) {
    				$img = $imgs->item($i);
    				$src = trim($img->getAttribute('src'));
    
    				$img->removeAttribute('width');
    				$img->removeAttribute('height');

    Here is the new code (added check to see if it was already smaller than max width

    /*
    Filter content for an advanced mobile device
    */
    function websitez_filter_advanced_page($html){
    	if (class_exists('DOMDocument')) {
    		try{
    			//Resize the images on the page
    			$dom = new DOMDocument();
    			$dom->loadHTML($html);
    
    			// grab all the on the page and make sure they are the right size
    			$xpath = new DOMXPath($dom);
    			$imgs = $xpath->evaluate("/html/body//img");
    
    			for ($i = 0; $i < $imgs->length; $i++) {
    				$img = $imgs->item($i);
    				$src = trim($img->getAttribute('src'));
    
    				if ($img->getAttribute('width') <= WEBSITEZ_ADVANCED_MAX_IMAGE_WIDTH) {
    					continue;
    				}
    
    				$img->removeAttribute('width');
    				$img->removeAttribute('height');

    http://wordpress.org/plugins/wp-mobile-detector/

  2. websitezcom
    Member
    Plugin Author

    Posted 2 years ago #

    Hm, there should have been a check in there. Thanks for bringing that to my attention.

    I will look back at the code and see when it was removed.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.