I need to get images by its position and I need each image resized to a concrete heigh and width.

If I want a image by its position I can do it by this code:

    ->getItemByColumnValue('position', 1)

//get image at position 1

And I know how to resize an image with this code:

echo $product
        ->init($_product, 'image')
        ->resize(900, 400);

But this code resizes the image set as image (or thumbnail, or small_image) but I don't know how to resize the image set at certain position (for example 2).

How can I merge both codes to resize the image at a certain position?

1 Answer 1


I found a solution, this works, at least in the catalog/product/view templates:

    $_imgSize = 630; 
    $_imgSizeHeight = 945;
<?php $i=0; foreach ($this->getGalleryImages() as $_image): ?>
    <?php if ($this->isGalleryImageVisible($_image)): ?>
        // at 'position default' set the number of the position you need
        <?php if($_image['position_default'] == 1): ?>  
            <a class="product-view-gallery" data-fancybox="gallery" data-caption="<?php echo $_product->getName(); ?>" href="<?php echo $this->getGalleryImageUrl($_image); ?>"><img id="image-<?php echo $i; ?>" class="gallery-image" src="<?php 

                echo $this
                        ->resize($_imgSize, $_imgSizeHeight);

             ?>" data-zoom-image="<?php echo $this->getGalleryImageUrl($_image); ?>" /></a>
        <?php endif; ?>
    <?php endif; ?>
<?php $i++; endforeach; ?>

Maybe it helps somebody in the future

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.