public function pixum($width = 150, $height = false)
{
$cache_folder = media_base_path() . 'pixum' . DS;
if ($height) {
$h = $height;
} else {
$h = $width;
}
$h = intval($h);
$w = intval($width);
if ($h == 0) {
$h = 1;
}
if ($w == 0) {
$w = 1;
}
$extension = '.png';
$hash = 'pixum-' . $h . 'x' . $w;
$cachefile = normalize_path($cache_folder . DS . $hash . $extension, false);
if (!file_exists($cachefile)) {
$dirname_file = dirname($cachefile);
if (!is_dir($dirname_file)) {
mkdir_recursive($dirname_file);
}
$img = imagecreatetruecolor($w, $h);
$white = imagecolorallocatealpha($img, 239, 236, 236, 0);
imagefill($img, 0, 0, $white);
imagealphablending($img, false);
imagesavealpha($img, true);
imagepng($img, $cachefile);
imagedestroy($img);
}
if (file_exists($cachefile)) {
$url = media_base_url() . 'pixum/' . $hash . $extension;
} else {
$url = $this->app->url_manager->site('api_nosession/pixum_img') . '?width=' . $width . '&height=' . $height;
}
return $url;
}