Resize image in Magento admin product edit image tab


Are you searching for Magento admin gallery images resize code?

Magento is complex platform and it’s very hard to customized or edit any core file.

If Magento admin uploading high-resolution and high-quality images for products and these high-quality images are making product edit page slow.

So if you look at a custom code resize Magento admin gallery images.

As a Magento developer, you know Magento admin show default image size is 100px. But image load full size. Due to full-size image page load is slow.

I think you are a Magento developer, so no need for extra explanation.

Add this following code. It will fix this issue.
File Name and Path:

/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php

public function afterLoad($object){
        $attrCode = $this->getAttribute()->getAttributeCode();
        $value = array();
        $value['images'] = array();
        $value['values'] = array();
		
        $localAttributes = array('label', 'position', 'disabled','file');
		// add file element.
        foreach ($this->_getResource()->loadGallery($object, $this) as $key => $image){
		
            foreach ($localAttributes as $localAttribute) {
			  
			    /* Custom start here */
                if ($localAttribute == 'file') {
					if (Mage::app()->getStore()->isAdmin()) {
						$image_url = (string) Mage::helper('catalog/image')->init($object, 'small_image',$image['file'])->keepFrame(false)->resize(100);
						$image_url =  substr($image_url,strpos($image_url,'cache'));
						$image[$localAttribute] = $image_url;
					}
				}
				/* Custom end here */
				if (is_null($image[$localAttribute])) {
					$image[$localAttribute] = $this->_getDefaultValue($localAttribute, $image);
				}
            }
            $value['images'][] = $image;
        }
        $object->setData($attrCode, $value);
    }