| | 1285 | # generate thumbnail |
|---|
| | 1286 | $src_file = asset_path($asset['asset_file_path'], $blog); |
|---|
| | 1287 | |
|---|
| | 1288 | $cache_path = $mt->config('AssetCacheDir'); |
|---|
| | 1289 | $image_path = $cache_path . DIRECTORY_SEPARATOR . 'userpics'; |
|---|
| | 1290 | $static_file_path = static_file_path().'support'; |
|---|
| | 1291 | make_thumbnail_file($src_file, $static_file_path.DIRECTORY_SEPARATOR.$image_path.DIRECTORY_SEPARATOR.$filename, $max_dim, $max_dim, 0, 'png'); |
|---|
| | 1292 | |
|---|
| | 1293 | $static_path = $mt->config('StaticWebPath'); |
|---|
| | 1294 | $static_path = preg_replace('/\/$/', '', $static_path); |
|---|
| | 1295 | $static_path .= '/support'; |
|---|
| 1298 | | function get_thumbnail_file($asset, $blog, $width = 0, $height = 0, $scale = 0, $format = '%f-thumb-%wx%h%x') { |
|---|
| 1299 | | # Get parameter |
|---|
| 1300 | | $site_path = $blog['blog_site_path']; |
|---|
| 1301 | | $site_path = preg_replace('/\/$/', '', $site_path); |
|---|
| 1302 | | $filename = asset_path($asset['asset_file_path'], $blog); |
|---|
| 1303 | | |
|---|
| | 1301 | function make_thumbnail_file($src, $dest, $width, $height, $scale = 0, $dest_type = 'auto') { |
|---|
| | 1340 | |
|---|
| | 1341 | # Generate |
|---|
| | 1342 | if(!file_exists($dest)) { |
|---|
| | 1343 | $dir_name = dirname($dest); |
|---|
| | 1344 | if (!file_exists($dir_name)) { |
|---|
| | 1345 | mkdir($dir_name, 0777, true); |
|---|
| | 1346 | } |
|---|
| | 1347 | if (!is_writable($dir_name)) { |
|---|
| | 1348 | imagedestroy($src_img); |
|---|
| | 1349 | return ''; |
|---|
| | 1350 | } |
|---|
| | 1351 | |
|---|
| | 1352 | # Create thumbnail |
|---|
| | 1353 | $dst_img = imagecreatetruecolor ( $thumb_w, $thumb_h ); |
|---|
| | 1354 | $result = imagecopyresampled ( $dst_img, $src_img, 0, 0, 0, 0, |
|---|
| | 1355 | $thumb_w, $thumb_h, $src_w, $src_h); |
|---|
| | 1356 | |
|---|
| | 1357 | $output = $src_type; |
|---|
| | 1358 | if ($dest_type != 'auto') { |
|---|
| | 1359 | $output = strtolower($dest_type) == 'gif' ? 1 |
|---|
| | 1360 | : strtolower($dest_type) == 'jpeg' ? 2 |
|---|
| | 1361 | : strtolower($dest_type) == 'png' ? 3 |
|---|
| | 1362 | : $src_type; |
|---|
| | 1363 | } |
|---|
| | 1364 | switch($output) { |
|---|
| | 1365 | case 1: #GIF |
|---|
| | 1366 | imagegif($dst_img, $dest); |
|---|
| | 1367 | break; |
|---|
| | 1368 | case 2: #JPEG |
|---|
| | 1369 | imagejpeg($dst_img, $dest); |
|---|
| | 1370 | break; |
|---|
| | 1371 | case 3: #PNG |
|---|
| | 1372 | imagepng($dst_img, $dest); |
|---|
| | 1373 | break; |
|---|
| | 1374 | } |
|---|
| | 1375 | imagedestroy($dst_img); |
|---|
| | 1376 | } |
|---|
| | 1377 | |
|---|
| | 1378 | imagedestroy($src_img); |
|---|
| | 1379 | |
|---|
| | 1380 | return array($thumb_w, $thumb_h); |
|---|
| | 1381 | } |
|---|
| | 1382 | |
|---|
| | 1383 | function get_thumbnail_file($asset, $blog, $width = 0, $height = 0, $scale = 0, $format = '%f-thumb-%wx%h%x') { |
|---|
| | 1384 | # Get parameter |
|---|
| | 1385 | $site_path = $blog['blog_site_path']; |
|---|
| | 1386 | $site_path = preg_replace('/\/$/', '', $site_path); |
|---|
| | 1387 | $filename = asset_path($asset['asset_file_path'], $blog); |
|---|
| | 1388 | $name_w = 'auto'; $name_h = 'auto'; |
|---|
| | 1389 | if ($width > 0) |
|---|
| | 1390 | $name_w = $width; |
|---|
| | 1391 | if ($height > 0) |
|---|
| | 1392 | $name_h = $height; |
|---|
| 1374 | | if(!file_exists($thumb_name)) { |
|---|
| 1375 | | if (!file_exists($cache_dir)) { |
|---|
| 1376 | | mkdir($cache_dir, 0777, true); |
|---|
| 1377 | | } |
|---|
| 1378 | | if (!is_writable($cache_dir)) |
|---|
| 1379 | | return ''; |
|---|
| 1380 | | # Create thumbnail |
|---|
| 1381 | | $dst_img = imagecreatetruecolor ( $thumb_w, $thumb_h ); |
|---|
| 1382 | | $result = imagecopyresampled ( $dst_img, $src_img, 0, 0, 0, 0, |
|---|
| 1383 | | $thumb_w, $thumb_h, $src_w, $src_h); |
|---|
| 1384 | | |
|---|
| 1385 | | switch($src_type) { |
|---|
| 1386 | | case 1: #GIF |
|---|
| 1387 | | imagegif($dst_img, $thumb_name); |
|---|
| 1388 | | break; |
|---|
| 1389 | | case 2: #JPEG |
|---|
| 1390 | | imagejpeg($dst_img, $thumb_name); |
|---|
| 1391 | | break; |
|---|
| 1392 | | case 3: #PNG |
|---|
| 1393 | | imagepng($dst_img, $thumb_name); |
|---|
| 1394 | | break; |
|---|
| 1395 | | } |
|---|
| 1396 | | imagedestroy($dst_img); |
|---|
| 1397 | | } |
|---|
| 1398 | | |
|---|
| 1399 | | imagedestroy($src_img); |
|---|
| | 1419 | |
|---|
| | 1420 | # generate thumbnail |
|---|
| | 1421 | list ($thumb_w, $thumb_h) = make_thumbnail_file($filename, $thumb_name, $width, $height); |
|---|