I want to resize image without loss quality in magento 2 i used code

 $imageResize = $this->_imageFactory->create();
 $imageResize->resize($width, $height);
    //destination folder                
 $destination = $imageResized;
    //save image    

when i resize it reduce the quality of image as compare to original image. How can i resize without losing quality?

1 Answer 1


You can resize product image using below code.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository');
$productImageHelper = $objectManager->get('\Magento\Catalog\Helper\Image');

$productId = 1; ///  change your product ID
$width = 150; /// Change as per your requirement
$height = 150; /// Change as per your requirement
$image_type = 'thumbnail';

$product = $productRepository->getById($productId);
$resizedImage = $productImageHelper->init($product, $image_type)
                                   ->resize($width, $height);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.