Reputation: 1268
I'm building a thumbnail constructor with phpThumb (the James Heinrich implementation available here). Basically, I'm encapsulating the phpThumb
class to build thumbnails with a syntax like this:
$thumbnail = \Helpers\Images::getThumbnail("/assets/images/sample.png", [
"width" => 150,
"filters" => [
"grayscale"
]
]);
This checks if the image I'm asking a thumbnail for with the given set of options and filters exists and, if it does, it just gives me the URL to this resource. In case it doesn't, it processes the image, save the resulting thumbnail and gives me the URL to this newly created resource.
So far, so good. My problem comes when I try to add more than one filter like this:
$thumbnail = \Helpers\Images::getThumbnail("/assets/images/sample.png", [
"width" => 150,
"filters" => [
"blur" => 25,
"grayscale"
]
]);
Internally, I do this:
/**
* more filter cases here
*/
} elseif ($filter === "blur") {
if (!empty($parameters)) {
if (sizeof($parameters === 1)) {
$value = current($parameters);
if (is_numeric($value)) {
if ($value >= 0) {
if ($value <= 25) {
$phpthumb->setParameter("fltr", implode("|", [
$filters[$filter],
$value
]));
}
}
}
}
}
} elseif ($filter === "brightness") {
/**
* more filter cases here
*/
$filters[$filter]
is just an associative array with the different filter opcodes like usm
(unsharpen), gblr
(gaussian blur) and so on.
Seems like invoking the setParameter()
method multiple times is not working like I want (or like it should).
Is there a way to stack different filters together using the OO approach?
Upvotes: 0
Views: 234
Reputation: 1268
Nevermind, I solved it by changing the core logic. Calling the setParameter()
method out of the loop with all operations stored in array format fixed my problem.
Upvotes: 0