staempfli / magento2-module-image-resizer Goto Github PK
View Code? Open in Web Editor NEWMagento 2 Module to add simple image resizing capabilities in all blocks and .phtml templates
Magento 2 Module to add simple image resizing capabilities in all blocks and .phtml templates
Hi,
Is there any possibility to add watermarks to resized images, the way Magento 2 does this too?
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);
}
}
}
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?
As far as I can see, there is no way to set the compression of the images, right?
I am optimizing page speed right now, and the images in general are a big problem because of too little or no compression
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
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?
Great extension, I was wondering if you could integrate adaptive resizing into it (similar to this other extension) it's probably out of scope but I find it very useful.
As I can see this is the part of the code that handles the resizing but I haven't been able to integrate into this extension:
https://github.com/trive-digital/AdaptiveResizeM2/blob/master/Model/Product/Image.php#L66-L80
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
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" }}">
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" />
Cool module! I implemented it into a project I'm working on, it works great. A few suggestions, though:
Please let me know what your thoughts are, I'm willing to contribute!
I had to create my own class to get it working:
<?php
namespace Marissen\QuotationSheet\Helper;
use Magento\Catalog\Model\Product;
use Staempfli\ImageResizer\Model\Resizer;
class ImageResizer extends Resizer
{
public function getPath(Product $product): string
{
$imageObject = $product->getMediaGalleryImages()->getFirstItem();
if (!$imageObject->getData('url')) {
return '';
}
$this->resizeAndGetUrl($imageObject->getData('url'), 200, 200);
return $this->getAbsolutePathResized() ?: '';
}
}
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
First of all, thanks for this module.
It was wonderful when turning category images into responsive images with srcset and sizes attributes.
One thing that I would love to see is the feature to use it outside of templates, but as widget in the admin section.
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 [] []
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.