Magento 2 Module to add simple image resizing capabilities in all blocks and .phtml templates

Overview

Magento 2 Image Resizer

Project Status: Abandoned – Initial development has started, but there has not yet been a stable, usable release; the project has been abandoned and the author(s) do not intend on continuing development.

Magento 2 Module to add simple image resizing capabilities in all blocks and .phtml templates

Installation

$ composer require "staempfli/magento2-module-image-resizer":"~2.0"

Usage

imageResizer is automatically available in all frontend Blocks. You can resize your images just calling a method:

/** @var \Staempfli\ImageResizer\Model\Resizer $imageResizer */
$imageResizer = $block->getImageResizer();
$resizedImageUrl = $imageResizer->resizeAndGetUrl(<originalImageUrl>, $width, $height, [$resizeSettings]); 

You can do that directly on the .phtml or in your custom Block.

Cache

Resized images are saved in cache to improve performance. That way, if an image was already resized, we just use the one in cache.

If you need to, you can clear the resized images cache on the Admin Cache Management

Admin Clear Resized Images Cache

Prerequisites

  • PHP >= 7.0.*
  • Magento >= 2.1.*
Comments
  • does not support theme images

    does not support theme images

    This module assumes, that the images reside in /pub/media. But what about images from /pub/static? E.g. any images from themes. Is this module not supposed to support those files as well?

    Feature request 
    opened by fritzmg 4
  • fopen with url error

    fopen with url error

    Hi,

    I updated your extension to 2.1.0 and I had problem in the frontend by every category page: (I use Magento Community Edition 2.2.7.)

    2019-03-18 09:54:58] main.CRITICAL: Warning: fopen(<<url>>): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in <<url>>/src/vendor/staempfli/magento2-module-image-resizer/Model/Resizer.php on line 315 [] []

    I think: $filepointer = fopen($file, "rb"); fopen with urls is usaually disallowed on productions servers

    With the version 2.0.3 I don't have problem.

    Can you fix it?

    Best regards, Adam

    opened by adamvarga 3
  • Directory separator incorrectly used for URL in getResizedImageUrl()

    Directory separator incorrectly used for URL in getResizedImageUrl()

    Hi,

    On Windows machines the use of the directory separator in getRelativePathResizedImage() which is called within getResizedImageUrl causes issues as URL's are generated in the following format.

    http://domain.com/media/staempfli_imageresizer\cache\wysiwyg\638x372_co_ar_tr_85\filename.jpg

    Suggest changing DIRECTORY_SEPARATOR to just use '/' for full OS support.

    Shall I do a PR for this?

    opened by clivewalkden 3
  • Original Image is used when using CDN

    Original Image is used when using CDN

    Yesterday we switched to a CDN (Cloudfront). It works fine but the resized images via this module are wrong. It is always outputting the original image path, which leads to a page speed disaster right now.

    Updated to latest version 2.0.2 Magento 2.2.4 PHP7 Varnish Nginx

    Expected Output:

    <img src="https://d2rblablablaqf.cloudfront.net/staempfli_imageresizer/cache/catalog/category/182x182_co_ar_tr/niceimage.png" >

    Actual Output

    <img src="https://d2rblablablaqf.cloudfront.net/catalog/category/niceimage.png" />

    opened by johnny-longneck 2
  • initRelativeFilenameFromUrl doesn't take into account cdn url

    initRelativeFilenameFromUrl doesn't take into account cdn url

    Resizer doesn't work if you have a media url different from your imageUrl. Example : base site : www.example.com => base of the imageUrl media url : cdn.example.com => strpos fails

    fix => use the parse_url function

    enhancement 
    opened by gtlt 2
  • Set backgroundColor image

    Set backgroundColor image

    Any plans to add functionality to change the background color? Default is white in Magento.

    https://github.com/magento/magento2/blob/develop/app/code/Magento/Catalog/Helper/Image.php

    opened by PieterCappelle 2
  • Images dont resize if the url path is given for an image assigned to the catalog/product/

    Images dont resize if the url path is given for an image assigned to the catalog/product/

    Staempfli\ImageResizer\Model\Resizer: initRelativeFilenameFromUrl() this gets the image path based relative to the /cache/ folder.

    protected function initRelativeFilenameFromUrl(string $imageUrl)
        {
            $this->relativeFilename = false; // reset filename in case there was another value defined
            $mediaUrl = $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA);
            $mediaPath = parse_url($mediaUrl, PHP_URL_PATH);
            $imagePath = parse_url($imageUrl, PHP_URL_PATH);
    
            if (false !== strpos($imagePath, $mediaPath)) {
    			
                $this->relativeFilename = str_replace($mediaPath, '', $imagePath);
    			if(strstr($this->relativeFilename,"/cache/"))
    			{
    				list($first,$second) = explode("/cache/",$this->relativeFilename);
    				
    				$path = explode("/",$second);
    				array_shift($path);
    				$this->relativeFilename = $first . "/" . implode("/",$path);
    			}
    				
            }
    		
        }
    
    enhancement 
    opened by pmathbliss 1
  • Add support for watermark images

    Add support for watermark images

    Fixes #25

    Simply passes the resizeSettings for the watermark along to the watermark function of the specified image adapter. But only if the imagePath can be found.

    opened by indykoning 0
  • Feature request: CMS syntax support

    Feature request: CMS syntax support

    Hi, it would be awesome to use the cms syntax for image processing.. some kind of this:

    <img src="{{staempflimage src="media/wysiwyg/image.png" image-resize="200x" image-quality="75" }}">

    opened by Detzler 0
  • Greatly improved speed if image is not a gif

    Greatly improved speed if image is not a gif

    Using this module before with 10 images (Not gif images) took 4 seconds in total. Using this module with this edit it will be able to do this in 1 second.

    Those benchmarks were done on images that have already been cached already.

    All the file operations are relatively heavy, instead of starting with those do a very simple check if we are even dealing with a gif.

    opened by indykoning 0
  • isAnimatedGif fails on local domain

    isAnimatedGif fails on local domain

    My development setup is based on Valet Plus. Local usage of this module results in this error:

    [2020-01-20 09:18:12] main.ERROR: Staempfli_ImageResizer: could not find image: 
    Warning: fopen(): SSL operation failed with code 1. OpenSSL Error messages:
    error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in vendor/staempfli/magento2-module-image-resizer/Model/Resizer.php on line 318 [] []
    
    opened by rikwillems 0
Owner
Stämpfli AG
Web solutions for associations, small businesses and more.
Stämpfli AG
CloudFlare Image Resizing plugin for WordPress.

Cloudflare Image Resizing plugin for WordPress The current Cloudflare plugin for WordPress does not replace URL's automatically for you to use the Ima

Norbert Boros 43 Jan 7, 2023
Converts any PocketMine-MP 3.0 extended blocks into PM4 native blocks!

ExtendedBlocksConverter Converts any PocketMine-MP 3.0 extended blocks into PM4 native blocks! Yes, you heard right, this plugin can convert any lefto

Covered123 6 Jun 4, 2022
A Magento 2 module that allows admins to duplicate CMS blocks and pages from their respective grids and en masse.

element119 | CMS Duplicator ?? Features ✔️ Allows merchants to duplicate CMS blocks and pages from the Action column in the admin grid ✔️ Allows merch

Kiel Pykett 13 Oct 13, 2022
Magento 2 Module Experius Page Not Found 404. This module saves all 404 url to a database table

Magento 2 Module Experius Page Not Found 404 This module saves all 404 urls to a database table. Adds an admin grid with 404s It includes a count so y

Experius 28 Dec 9, 2022
Allow multiple options for Magento 2 checkout layout. Provides capabilities to AB test checkout changes and more.

Aimes_CheckoutDesigns Features Please note: This module is currently still considered a proof of concept. This module provides the ability to change c

Rob Aimes 30 Aug 8, 2022
More options when uploading files such as name changes, resizing or compression through TinyPNG.

Kirby Upload Extended More options when uploading files like name changes, resizing via Kirby or compression and optional resizing via TinyPNG. Thanks

Oli 24 Nov 12, 2022
A plugin to add more blocks to PocketMine

This plugin aims to add all blocks not included in PocketMine. As of right now the ExtendedBlocks plugin is required to add blocks with IDs above 255.

xSuper 26 Dec 19, 2022
Silverstripe module allowing editors to create newsletters using elemental blocks and export them to a sendy instance

Silverstripe Sendy Silverstripe module allowing editors to create newsletters using elemental blocks and export them to a sendy instance. Introduction

Syntro Opensource 4 Apr 20, 2022
❄️ Magento 2 Snowflake module allow you to add snow and even more on your site and make winter fun.

❄️ Magento 2 Snowflake module allow you to add snow and even more on your site and make winter fun.

OpenGento 6 Apr 30, 2022
A simple plugin to override all woocommerce templates

A simple plugin to override all woocommerce templates

null 10 Nov 16, 2021
WordPress plugin renames image filenames to be more SEO friendly, based on the post's data and image metadata.

=== Automatic image Rename === Contributors: wpsunshine Tags: image, images, SEO, rename, optimization Requires at least: 5.0 Tested up to: 6.2.2 Stab

null 8 Jun 11, 2023
Magento 2 Module that adds Donation Product Type. Enables the customer to add a donation (product) of a preferred amount to the cart.

Magento 2 Module Experius DonationProduct (RC1.0) Demo website: https://donationproduct.experius.nl Magento Marketplace: https://marketplace.magento.c

Experius 23 Apr 1, 2022
Allow SVG images to be used in Magento CMS blocks and pages via the TinyMCE Wysiwyg Editor.

Hyvä Themes - SVG support for the Magento CMS Wysiwyg Editor Allow SVG images to be used in CMS blocks and pages via the TinyMCE Wysiwyg Editor. hyva-

Hyvä 14 Dec 15, 2022
Docker-magento - Docker image for Magento 1.6 to 1.9

Docker image for Magento 1.x This repo creates a Docker image for Magento 1.x. Please note The primary goal of this repo is to create Docker images fo

Fu Cheng 144 Nov 18, 2022
The swiss army knife for Magento developers, sysadmins and devops. The tool provides a huge set of well tested command line commands which save hours of work time. All commands are extendable by a module API.

netz98 magerun CLI tools for Magento 2 The n98 magerun cli tools provides some handy tools to work with Magento from command line. Build Status Latest

netz98 758 Dec 28, 2022
An opinionated extension package for Laravel Orchid to extend its table handling capabilities, and some further useful helper methods.

OrchidTables An opinionated extension package for Laravel Orchid to extend its table handling capabilities, and some further useful helper methods. In

null 25 Dec 22, 2022
The FileLocator library was created to provide file locating capabilities to a larger project

File Locator A simple file locator library. Summary The FileLocator library was created to provide file locating capabilities to a larger project. It

KHerGe - Archived Projects 20 Dec 22, 2021