method thumbs documentation in bbn\File\Image
Creates miniature of the image
Example
$img = new bbn\File\Image("/home/data/test/image.jpg");
$img->thumbs()->save(/home/data/test/image_test.jpg");
function($dest = '.', $sizes = NULL, $mask = '_%s', $crop = false, $bigger = false)
{
if ($this->test() && is_dir($dest)) {
if (!is_array($sizes)) {
$sizes = Str::isInteger($sizes) ? [[$sizes, false]] : self::$defaultThumbSizes;
}
$this->getExtension();
$w = $this->getWidth();
$h = $this->getHeight();
$d = $w >= $h ? 'w' : 'h';
$res = [];
if ($$d / ($d === 'w' ? $h : $w) < 5) {
$file = ($dest === '.' ? '' : $dest.'/').$this->title;
//die(var_dump($mask));
foreach ($sizes as $s){
if (Str::isInteger($s)) {
$s = [$s, false];
}
if ((!empty($s[0]) && ($w > $s[0]))
|| (!empty($s[1]) && ($h > $s[1]))
|| $bigger
) {
$smask = [];
if (!empty($s[0])) {
$smask[] = 'w-' . $s[0];
if (!empty($s[1])) {
$mask .= '-%s';
}
}
if (!empty($s[1])) {
$smask[] = 'h-' . $s[1];
}
if ($crop) {
$mask .= '-%s';
$smask[] = 'c-1';
}
if ($s[0] && $s[1]) {
if ($crop) {
$this->resize($s[0], $s[1], true);
}
else{
$this->resize($d === 'w' ? $s[0] : false, $d === 'h' ? $s[1] : false, false, $s[0], $s[1]);
}
}
else{
$this->resize($s[0], $s[1], $crop);
}
$sm = sprintf($mask, ...$smask);
$fn = $file.$sm.'.'.$this->ext;
$this->save($fn);
$res[$sm] = $fn;
}
}
return $res;
}
}
return false;
}
Creates miniature of the image BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2025
BBN Solutions