I have this ColorThief\ColorThief
package that works well inside a controller.
However, I want to create a function getImageColor($imgName)
in helper.php
to consume ColorThief\ColorThief
so I can use getImageColor($imgName)
directly from views.
How can I access ColorThief\ColorThief
from inside helper.php
.
use ColorThief\ColorThief;
function getImageColor($img='') {
if(!empty($img)) {
$upload_path = public_path() . '/uploads/'.$img;
if(file_exists($upload_path)) {
return ColorThief::getColor($upload_path);
}
}
return false;
}
When I call getImageColor('image.jpg')
, I get the following error:
htmlspecialchars() expects parameter 1 to be string, array given (View: /home/userxyz/public_html/dev/resources/views/welcome.blade.php)
Please note that when ColorThief::getColor($upload_path);
is used inside a controller, it works perfectly.