Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Surface chroma-subsampling options #121

Open
badbadmonkey opened this issue Jul 10, 2018 · 3 comments
Open

Suggestion: Surface chroma-subsampling options #121

badbadmonkey opened this issue Jul 10, 2018 · 3 comments

Comments

@badbadmonkey
Copy link

badbadmonkey commented Jul 10, 2018

Just a suggestion - at present phpThumb provides no control over chroma subsampling of JPEGs produced, relying on the defaults for sampling-factor with ImageMagick. I wonder if such control might be surfaced along with defaults.

For example I currently hack phpThumb.class.php as follows just above the final lines generating $commandline ~

if ($this->thumbnailFormat == 'jpg' || $this->thumbnailFormat == 'jpeg') {
	if ($this->thumbnailQuality <= 65) $commandline .= ' -sampling-factor 2x2';		// 4:2:0 commensurate with lower q
	elseif ($this->thumbnailQuality <= 70) $commandline .= ' -sampling-factor 2x1';	// 4:2:2 for medium q
	else $commandline .= ' -sampling-factor 1x1';		// 4:4:4 for higher q
}

Which hard-codes my own preferences but obviously options would be better. I think it's particularly useful nowadays with us having to deal with both low and high dpi client screens.

The other logic that would be useful to build in would be graceful degradation of the setting so that a higher subsampling wasn't used than the source JPG justified. This is where phpThumb has a role to play beyond the defaults from ImageMagick.

For example if a 1000px 4:2:0 JPG is resized to 500px, the thumbnail could be subsampled at 4:4:4 if the user settings desired it, but not if it's resized to say 800px. On the other hand a 4:4:4 source would justify the same at any downsize resolution.

@JamesHeinrich
Copy link
Owner

Since you're more familiar with the issue than I, could you apply whatever modifications you think appropriate and submit a pull request.

@badbadmonkey
Copy link
Author

My hack above just implements what I think appropriate for my particular site. I wouldn't advocate it for all. I'm just throwing the idea here to try to put it on your radar as it's become more of an optimization issue lately.

What I would suggest is firstly adding core support with sensible defaults, but also surfacing control in the config or defaults, and adding an URL parameter at least just accessing -sampling-factor, to allow smart usage when it comes to using srcset and for varying screen densities. I lack the in-depth familiarity with phpThumb to do that in a satisfactory way sorry!

@JamesHeinrich
Copy link
Owner

If you would like to have it in phpThumb, I leave it to you (or someone) to suggest and submit an implementation. I'm essentially unfamiliar with the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants