CollectionFactory get image, thumbnail, small_image are the same












1















In my custom block, I get Product Collection use MagentoCatalogModelResourceModelProductCollectionFactory, when I output one product in it, the image, thumbnail, small_image are the same url like below, a large image(1380px x 1340px) url:



[image] => /m/b/mb04-black-0.jpg
[small_image] => /m/b/mb04-black-0.jpg
[thumbnail] => /m/b/mb04-black-0.jpg


Did I do something wrong? How do I get the real small_image or thumbnail URL from product collection?



More question description



For example, in the default luma theme category, product list always get the image like below:



<img class="product-image-photo" src="http://local.com/pub/media/catalog/product/cache/small_image/240x300/beff4985b56e3afdbeabfc89641a4582/w/t/wt09-white_main.jpg" width="240" height="300" alt="Breathe-Easy Tank">


How can I get that?



My code example



Below is my code, I remove some function for simplicity.



<?php
namespace VendorTemplateBlock;

use MagentoFrameworkViewElementTemplate;
use MagentoBackendBlockTemplateContext;
use MagentoCatalogModelResourceModelProductCollectionFactory;

class Product extends Template
{
protected $_productCollectionFactory;

public function __construct(
Context $context,
CollectionFactory $productCollectionFactory,
array $data =
)
{
$this->_productCollectionFactory = $productCollectionFactory;
parent::__construct($context, $data);
}

public function getProductCollection()
{
$skus = $this->getData('products_count');
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToSelect('*')
->addAttributeToFilter(
'sku', array('in' => $skus)
);
return $collection;
}
}









share|improve this question

























  • can you provide your code that you have used.

    – Suman-PHP4U
    Sep 7 '17 at 9:22











  • @Suman-PHP4U Hi, add the code now. Thank you for any help.

    – Key Shang
    Sep 7 '17 at 9:40
















1















In my custom block, I get Product Collection use MagentoCatalogModelResourceModelProductCollectionFactory, when I output one product in it, the image, thumbnail, small_image are the same url like below, a large image(1380px x 1340px) url:



[image] => /m/b/mb04-black-0.jpg
[small_image] => /m/b/mb04-black-0.jpg
[thumbnail] => /m/b/mb04-black-0.jpg


Did I do something wrong? How do I get the real small_image or thumbnail URL from product collection?



More question description



For example, in the default luma theme category, product list always get the image like below:



<img class="product-image-photo" src="http://local.com/pub/media/catalog/product/cache/small_image/240x300/beff4985b56e3afdbeabfc89641a4582/w/t/wt09-white_main.jpg" width="240" height="300" alt="Breathe-Easy Tank">


How can I get that?



My code example



Below is my code, I remove some function for simplicity.



<?php
namespace VendorTemplateBlock;

use MagentoFrameworkViewElementTemplate;
use MagentoBackendBlockTemplateContext;
use MagentoCatalogModelResourceModelProductCollectionFactory;

class Product extends Template
{
protected $_productCollectionFactory;

public function __construct(
Context $context,
CollectionFactory $productCollectionFactory,
array $data =
)
{
$this->_productCollectionFactory = $productCollectionFactory;
parent::__construct($context, $data);
}

public function getProductCollection()
{
$skus = $this->getData('products_count');
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToSelect('*')
->addAttributeToFilter(
'sku', array('in' => $skus)
);
return $collection;
}
}









share|improve this question

























  • can you provide your code that you have used.

    – Suman-PHP4U
    Sep 7 '17 at 9:22











  • @Suman-PHP4U Hi, add the code now. Thank you for any help.

    – Key Shang
    Sep 7 '17 at 9:40














1












1








1








In my custom block, I get Product Collection use MagentoCatalogModelResourceModelProductCollectionFactory, when I output one product in it, the image, thumbnail, small_image are the same url like below, a large image(1380px x 1340px) url:



[image] => /m/b/mb04-black-0.jpg
[small_image] => /m/b/mb04-black-0.jpg
[thumbnail] => /m/b/mb04-black-0.jpg


Did I do something wrong? How do I get the real small_image or thumbnail URL from product collection?



More question description



For example, in the default luma theme category, product list always get the image like below:



<img class="product-image-photo" src="http://local.com/pub/media/catalog/product/cache/small_image/240x300/beff4985b56e3afdbeabfc89641a4582/w/t/wt09-white_main.jpg" width="240" height="300" alt="Breathe-Easy Tank">


How can I get that?



My code example



Below is my code, I remove some function for simplicity.



<?php
namespace VendorTemplateBlock;

use MagentoFrameworkViewElementTemplate;
use MagentoBackendBlockTemplateContext;
use MagentoCatalogModelResourceModelProductCollectionFactory;

class Product extends Template
{
protected $_productCollectionFactory;

public function __construct(
Context $context,
CollectionFactory $productCollectionFactory,
array $data =
)
{
$this->_productCollectionFactory = $productCollectionFactory;
parent::__construct($context, $data);
}

public function getProductCollection()
{
$skus = $this->getData('products_count');
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToSelect('*')
->addAttributeToFilter(
'sku', array('in' => $skus)
);
return $collection;
}
}









share|improve this question
















In my custom block, I get Product Collection use MagentoCatalogModelResourceModelProductCollectionFactory, when I output one product in it, the image, thumbnail, small_image are the same url like below, a large image(1380px x 1340px) url:



[image] => /m/b/mb04-black-0.jpg
[small_image] => /m/b/mb04-black-0.jpg
[thumbnail] => /m/b/mb04-black-0.jpg


Did I do something wrong? How do I get the real small_image or thumbnail URL from product collection?



More question description



For example, in the default luma theme category, product list always get the image like below:



<img class="product-image-photo" src="http://local.com/pub/media/catalog/product/cache/small_image/240x300/beff4985b56e3afdbeabfc89641a4582/w/t/wt09-white_main.jpg" width="240" height="300" alt="Breathe-Easy Tank">


How can I get that?



My code example



Below is my code, I remove some function for simplicity.



<?php
namespace VendorTemplateBlock;

use MagentoFrameworkViewElementTemplate;
use MagentoBackendBlockTemplateContext;
use MagentoCatalogModelResourceModelProductCollectionFactory;

class Product extends Template
{
protected $_productCollectionFactory;

public function __construct(
Context $context,
CollectionFactory $productCollectionFactory,
array $data =
)
{
$this->_productCollectionFactory = $productCollectionFactory;
parent::__construct($context, $data);
}

public function getProductCollection()
{
$skus = $this->getData('products_count');
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToSelect('*')
->addAttributeToFilter(
'sku', array('in' => $skus)
);
return $collection;
}
}






magento2 product-images product-collection






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 7 '17 at 10:04







Key Shang

















asked Sep 7 '17 at 8:47









Key ShangKey Shang

1,5561034




1,5561034













  • can you provide your code that you have used.

    – Suman-PHP4U
    Sep 7 '17 at 9:22











  • @Suman-PHP4U Hi, add the code now. Thank you for any help.

    – Key Shang
    Sep 7 '17 at 9:40



















  • can you provide your code that you have used.

    – Suman-PHP4U
    Sep 7 '17 at 9:22











  • @Suman-PHP4U Hi, add the code now. Thank you for any help.

    – Key Shang
    Sep 7 '17 at 9:40

















can you provide your code that you have used.

– Suman-PHP4U
Sep 7 '17 at 9:22





can you provide your code that you have used.

– Suman-PHP4U
Sep 7 '17 at 9:22













@Suman-PHP4U Hi, add the code now. Thank you for any help.

– Key Shang
Sep 7 '17 at 9:40





@Suman-PHP4U Hi, add the code now. Thank you for any help.

– Key Shang
Sep 7 '17 at 9:40










2 Answers
2






active

oldest

votes


















2














Then you should use `MagentoCatalogHelperImage ' resize the product image



$resizedImage = $this->_productImageHelper->init($product, 'product_small_image')
->constrainOnly(TRUE)
->keepAspectRatio(TRUE)
->keepTransparency(TRUE)
->keepFrame(FALSE)
->resize(200, 300);


Magento 2 resize category & product image



https://www.mageplaza.com/how-change-product-image-size-magento-2.html






share|improve this answer


























  • Thanks first, you maybe mistake my question, I can show the image, but my problem is when get image, thumbnail, small_image, they are all the same, I always get a big image, so my question is how can I get the small image? The real small_image or thumbnail URL

    – Key Shang
    Sep 7 '17 at 9:47











  • Mean you want resize image

    – Amit Bera
    Sep 7 '17 at 9:56











  • For example, in the default luma theme category, product list always get the image like /pub/media/catalog/product/cache/small_image/240x300/beff4985b56e3afdbeabfc89641a4582/w/t/wt09-white_main.jpg, how can i get that?

    – Key Shang
    Sep 7 '17 at 10:00











  • Please check update answer

    – Amit Bera
    Sep 7 '17 at 10:08











  • Up vote, the resize is a solution, but can we directly get the small image that category page generated? Instead of generating some new size version images.

    – Key Shang
    Sep 7 '17 at 10:18



















0














Get product image from Product in PHTML file for Magento 2



$_objectManager = MagentoFrameworkAppObjectManager::getInstance();
$imageHelper = $_objectManager->get('MagentoCatalogHelperImage');

<?php $thumbnail_image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl(); ?>

<?php $small_image_url = $imageHelper->init($product, 'product_small_image')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl(); ?>

<?php $base_image_url = $imageHelper->init($product, 'product_base_image')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl(); ?>




share























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f192339%2fcollectionfactory-get-image-thumbnail-small-image-are-the-same%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Then you should use `MagentoCatalogHelperImage ' resize the product image



    $resizedImage = $this->_productImageHelper->init($product, 'product_small_image')
    ->constrainOnly(TRUE)
    ->keepAspectRatio(TRUE)
    ->keepTransparency(TRUE)
    ->keepFrame(FALSE)
    ->resize(200, 300);


    Magento 2 resize category & product image



    https://www.mageplaza.com/how-change-product-image-size-magento-2.html






    share|improve this answer


























    • Thanks first, you maybe mistake my question, I can show the image, but my problem is when get image, thumbnail, small_image, they are all the same, I always get a big image, so my question is how can I get the small image? The real small_image or thumbnail URL

      – Key Shang
      Sep 7 '17 at 9:47











    • Mean you want resize image

      – Amit Bera
      Sep 7 '17 at 9:56











    • For example, in the default luma theme category, product list always get the image like /pub/media/catalog/product/cache/small_image/240x300/beff4985b56e3afdbeabfc89641a4582/w/t/wt09-white_main.jpg, how can i get that?

      – Key Shang
      Sep 7 '17 at 10:00











    • Please check update answer

      – Amit Bera
      Sep 7 '17 at 10:08











    • Up vote, the resize is a solution, but can we directly get the small image that category page generated? Instead of generating some new size version images.

      – Key Shang
      Sep 7 '17 at 10:18
















    2














    Then you should use `MagentoCatalogHelperImage ' resize the product image



    $resizedImage = $this->_productImageHelper->init($product, 'product_small_image')
    ->constrainOnly(TRUE)
    ->keepAspectRatio(TRUE)
    ->keepTransparency(TRUE)
    ->keepFrame(FALSE)
    ->resize(200, 300);


    Magento 2 resize category & product image



    https://www.mageplaza.com/how-change-product-image-size-magento-2.html






    share|improve this answer


























    • Thanks first, you maybe mistake my question, I can show the image, but my problem is when get image, thumbnail, small_image, they are all the same, I always get a big image, so my question is how can I get the small image? The real small_image or thumbnail URL

      – Key Shang
      Sep 7 '17 at 9:47











    • Mean you want resize image

      – Amit Bera
      Sep 7 '17 at 9:56











    • For example, in the default luma theme category, product list always get the image like /pub/media/catalog/product/cache/small_image/240x300/beff4985b56e3afdbeabfc89641a4582/w/t/wt09-white_main.jpg, how can i get that?

      – Key Shang
      Sep 7 '17 at 10:00











    • Please check update answer

      – Amit Bera
      Sep 7 '17 at 10:08











    • Up vote, the resize is a solution, but can we directly get the small image that category page generated? Instead of generating some new size version images.

      – Key Shang
      Sep 7 '17 at 10:18














    2












    2








    2







    Then you should use `MagentoCatalogHelperImage ' resize the product image



    $resizedImage = $this->_productImageHelper->init($product, 'product_small_image')
    ->constrainOnly(TRUE)
    ->keepAspectRatio(TRUE)
    ->keepTransparency(TRUE)
    ->keepFrame(FALSE)
    ->resize(200, 300);


    Magento 2 resize category & product image



    https://www.mageplaza.com/how-change-product-image-size-magento-2.html






    share|improve this answer















    Then you should use `MagentoCatalogHelperImage ' resize the product image



    $resizedImage = $this->_productImageHelper->init($product, 'product_small_image')
    ->constrainOnly(TRUE)
    ->keepAspectRatio(TRUE)
    ->keepTransparency(TRUE)
    ->keepFrame(FALSE)
    ->resize(200, 300);


    Magento 2 resize category & product image



    https://www.mageplaza.com/how-change-product-image-size-magento-2.html







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Sep 7 '17 at 10:07

























    answered Sep 7 '17 at 9:32









    Amit BeraAmit Bera

    57.5k1474172




    57.5k1474172













    • Thanks first, you maybe mistake my question, I can show the image, but my problem is when get image, thumbnail, small_image, they are all the same, I always get a big image, so my question is how can I get the small image? The real small_image or thumbnail URL

      – Key Shang
      Sep 7 '17 at 9:47











    • Mean you want resize image

      – Amit Bera
      Sep 7 '17 at 9:56











    • For example, in the default luma theme category, product list always get the image like /pub/media/catalog/product/cache/small_image/240x300/beff4985b56e3afdbeabfc89641a4582/w/t/wt09-white_main.jpg, how can i get that?

      – Key Shang
      Sep 7 '17 at 10:00











    • Please check update answer

      – Amit Bera
      Sep 7 '17 at 10:08











    • Up vote, the resize is a solution, but can we directly get the small image that category page generated? Instead of generating some new size version images.

      – Key Shang
      Sep 7 '17 at 10:18



















    • Thanks first, you maybe mistake my question, I can show the image, but my problem is when get image, thumbnail, small_image, they are all the same, I always get a big image, so my question is how can I get the small image? The real small_image or thumbnail URL

      – Key Shang
      Sep 7 '17 at 9:47











    • Mean you want resize image

      – Amit Bera
      Sep 7 '17 at 9:56











    • For example, in the default luma theme category, product list always get the image like /pub/media/catalog/product/cache/small_image/240x300/beff4985b56e3afdbeabfc89641a4582/w/t/wt09-white_main.jpg, how can i get that?

      – Key Shang
      Sep 7 '17 at 10:00











    • Please check update answer

      – Amit Bera
      Sep 7 '17 at 10:08











    • Up vote, the resize is a solution, but can we directly get the small image that category page generated? Instead of generating some new size version images.

      – Key Shang
      Sep 7 '17 at 10:18

















    Thanks first, you maybe mistake my question, I can show the image, but my problem is when get image, thumbnail, small_image, they are all the same, I always get a big image, so my question is how can I get the small image? The real small_image or thumbnail URL

    – Key Shang
    Sep 7 '17 at 9:47





    Thanks first, you maybe mistake my question, I can show the image, but my problem is when get image, thumbnail, small_image, they are all the same, I always get a big image, so my question is how can I get the small image? The real small_image or thumbnail URL

    – Key Shang
    Sep 7 '17 at 9:47













    Mean you want resize image

    – Amit Bera
    Sep 7 '17 at 9:56





    Mean you want resize image

    – Amit Bera
    Sep 7 '17 at 9:56













    For example, in the default luma theme category, product list always get the image like /pub/media/catalog/product/cache/small_image/240x300/beff4985b56e3afdbeabfc89641a4582/w/t/wt09-white_main.jpg, how can i get that?

    – Key Shang
    Sep 7 '17 at 10:00





    For example, in the default luma theme category, product list always get the image like /pub/media/catalog/product/cache/small_image/240x300/beff4985b56e3afdbeabfc89641a4582/w/t/wt09-white_main.jpg, how can i get that?

    – Key Shang
    Sep 7 '17 at 10:00













    Please check update answer

    – Amit Bera
    Sep 7 '17 at 10:08





    Please check update answer

    – Amit Bera
    Sep 7 '17 at 10:08













    Up vote, the resize is a solution, but can we directly get the small image that category page generated? Instead of generating some new size version images.

    – Key Shang
    Sep 7 '17 at 10:18





    Up vote, the resize is a solution, but can we directly get the small image that category page generated? Instead of generating some new size version images.

    – Key Shang
    Sep 7 '17 at 10:18













    0














    Get product image from Product in PHTML file for Magento 2



    $_objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $imageHelper = $_objectManager->get('MagentoCatalogHelperImage');

    <?php $thumbnail_image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl(); ?>

    <?php $small_image_url = $imageHelper->init($product, 'product_small_image')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl(); ?>

    <?php $base_image_url = $imageHelper->init($product, 'product_base_image')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl(); ?>




    share




























      0














      Get product image from Product in PHTML file for Magento 2



      $_objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $imageHelper = $_objectManager->get('MagentoCatalogHelperImage');

      <?php $thumbnail_image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl(); ?>

      <?php $small_image_url = $imageHelper->init($product, 'product_small_image')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl(); ?>

      <?php $base_image_url = $imageHelper->init($product, 'product_base_image')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl(); ?>




      share


























        0












        0








        0







        Get product image from Product in PHTML file for Magento 2



        $_objectManager = MagentoFrameworkAppObjectManager::getInstance();
        $imageHelper = $_objectManager->get('MagentoCatalogHelperImage');

        <?php $thumbnail_image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl(); ?>

        <?php $small_image_url = $imageHelper->init($product, 'product_small_image')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl(); ?>

        <?php $base_image_url = $imageHelper->init($product, 'product_base_image')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl(); ?>




        share













        Get product image from Product in PHTML file for Magento 2



        $_objectManager = MagentoFrameworkAppObjectManager::getInstance();
        $imageHelper = $_objectManager->get('MagentoCatalogHelperImage');

        <?php $thumbnail_image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl(); ?>

        <?php $small_image_url = $imageHelper->init($product, 'product_small_image')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl(); ?>

        <?php $base_image_url = $imageHelper->init($product, 'product_base_image')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl(); ?>





        share











        share


        share










        answered 9 mins ago









        AB SaiyadAB Saiyad

        594




        594






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f192339%2fcollectionfactory-get-image-thumbnail-small-image-are-the-same%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            What other Star Trek series did the main TNG cast show up in?

            Berlina muro

            Berlina aerponto