Jump to content

ImageSizer::convertToGreyscale() – issue when creating and saving a greyscale version of an image


tb76
 Share

Recommended Posts

Hi!
I want to create greyscaled versions of color images for a hover effect. In my template I am doing this:

$is = new ImageSizer('/path/to/filename.ext');
$is->convertToGreyscale('/path/to/filename_new.ext');

(In my real code I am using filenames from page fields – the above code is just a shortened example.)

Doing this, the original files always are overwritten. I checked the source code and found, that the optional parameter $dstFilename isn't passed through when calling convertToGreyscale. $dstFilename get's lost in /wire/core/ImageSizer.php:

/**
 * Convert image to greyscale (black and white)
 *
 * @return bool
 *
 */
public function convertToGreyscale() {
	return $this->getEngine()->convertToGreyscale();
}

I changed the method in /wire/core/ImageSizer.php to the follwoing code:

public function convertToGreyscale($dstFilename = '') {
	return $this->getEngine()->convertToGreyscale($dstFilename);
}

Now, my template code works, but I changed a core file.
I am wondering, if this is an issue with ImageSizer or if I am doing it wrong. Do I have to call convertToGreyscale in some other way?

Link to comment
Share on other sites

9 hours ago, tb76 said:

I want to create greyscaled versions of color images for a hover effect.

Your site visitors would have to download two copies of every image if you do this server-side. These days a CSS filter is the way to go:

.bw-image:hover { filter:grayscale(100%); }

And who cares about IE (or use a polyfill).

But if you're sure you want to do this in PW and set a destination filename...

$is = new ImageSizer('/path/to/filename.ext');
$is->getEngine()->convertToGreyscale('/path/to/filename_new.ext');

 

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...