public function thumbnail($src, $width = 200, $height = 200)
{
if ($src == false) {
return $this->pixum($width, $height);
}
$src = html_entity_decode($src);
$src = htmlspecialchars_decode($src);
$surl = $this->app->url_manager->site();
$src = str_replace('{SITE_URL}', $surl, $src);
$src = str_replace('%7BSITE_URL%7D', $surl, $src);
$base_src = str_replace($surl, '', $src);
if (!isset($width)) {
$width = 200;
}
$src = strtok($src, '?');
if (!isset($height)) {
$height = 200;
}
$cd = $this->thumbnails_path() . $width . DS;
$ext = strtolower(get_file_extension($base_src));
$cache = $base_src . $width . $height . '.' . $ext;
$cache = str_replace(' ', '_', $cache);
$ext = strtolower(get_file_extension($src));
$is_remote = false;
if (!stristr($src, $surl)) {
if (strstr($src, 'http://')) {
$is_remote = true;
} elseif (strstr($src, 'https://')) {
$is_remote = true;
}
}
$cache_id = array();
$cache_id['base_src'] = $base_src;
$cache_id['src'] = $src;
$cache_id['width'] = $width;
$cache_id['height'] = $height;
$cache_id = 'tn-' . md5(serialize($cache_id)) . '.' . $ext;
$cache_path = $cd . $cache_id;
if ($is_remote) {
return $src;
} elseif (file_exists($cache_path)) {
$cache_path = $this->app->url_manager->link_to_file($cache_path);
return $cache_path;
} else {
if (stristr($base_src, 'pixum_img')) {
return $this->pixum($width, $height);
}
$tn_img_url = $this->app->url_manager->site('api_html/thumbnail_img') . '?&src=' . $base_src . '&width=' . $width . '&height=' . $height . '&cache_id=' . $cache_id;
$tn_img_url = str_replace('(', '(', $tn_img_url);
$tn_img_url = str_replace(')', ')', $tn_img_url);
return $tn_img_url;
}
// $surl = $this->app->url_manager->site();
// $local = false;
//
// $media_url = media_base_url();
// $media_url = trim($media_url);
// $src = str_replace('{SITE_URL}', $surl, $src);
// $src = str_replace('%7BSITE_URL%7D', $surl, $src);
//
// if (strstr($src, $surl) or strpos($src, $surl)) {
// $src = str_replace($surl . '/', $surl, $src);
// $src = str_replace($surl, '', $src);
// $src = ltrim($src, DS);
// $src = ltrim($src, '/');
// $src = rtrim($src, DS);
// $src = rtrim($src, '/');
// $src = MW_ROOTPATH . $src;
// $src = normalize_path($src, false);
//
// } else {
// if ($src == false) {
// return $this->pixum($width, $height);
// }
// }
// $cd = media_base_path() . 'thumbnail' . DS;
// if (!is_dir($cd)) {
// mkdir_recursive($cd);
// }
//
// $cache = md5($src . $width . $height) . basename($src);
//
// $cache = str_replace(' ', '_', $cache);
// $cache_path = $cd . $cache;
//
// if (!file_exists($cache_path)) {
// if (file_exists($src)) {
// $src1 = $this->app->format->array_to_base64($src);
// $base_src = basename($src);
// $ext = get_file_extension($src);
// if (strtolower($ext) == 'svg') {
// $res1 = file_get_contents($src);
// $res1 = $this->svgScaleHack($res1, $width, $height);
// file_put_contents($cache_path, $res1);
// } else {
// $tn = new \Microweber\Thumbnailer($src);
// $thumbOptions = array('maxLength' => $height, 'width' => $width);
// $tn->createThumb($thumbOptions, $cache_path);
// unset($tn);
// }
// }
//
// }
// if (file_exists($cache_path)) {
// $cache_path = $this->app->url_manager->link_to_file($cache_path);
// return $cache_path;
// } else {
// return $this->pixum($width, $height);
// }
// return false;
}