I'm using Magento 2 CE Version 2.1.0
I have Custom Module with Image Field. When it's uploaded, i want different size images as for product we have
Thumbnail Image, List Image & Product Detail Page Image.
Able to upload 1 image without resize.
I'm using below code for resizing image, but it's giving product image URL. Not my custom module.
\app\code\Custom\Module\Block\MyPosts\Edit.php
public function getImage($posts, $image) {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$_imagehelper = $objectManager->get('Magento\Catalog\Helper\Image');
echo $postImage = $_imagehelper->init($posts, $image)->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(400)->getUrl();
exit;
}
It gives below URL http://localhost/magento2/pub/static/frontend/Magento/luma/en_US/Magento_Catalog/images/product/placeholder/.jpg
My image is stored here: \magento2\pub\media\custom_module\posts\image
.
How can i get resize image with this path & how can i save/retrieve different size image?
Best Answer
You can check in details by click, Resize Custom Image in Magento 2
Inside Block file keep below code,
Now Call inside phtml file,