| 1304 | | make_thumbnail_file($src_file, $static_file_path.DIRECTORY_SEPARATOR.$image_path.DIRECTORY_SEPARATOR.$filename, $max_dim, $max_dim, 0, 'png'); |
| | 1296 | |
| | 1297 | require_once('thumbnail_lib.php'); |
| | 1298 | $thumb = new Thumbnail($src_file); |
| | 1299 | $thumb_w = $max_dim; |
| | 1300 | $thumb_h = $max_dim; |
| | 1301 | $dest; |
| | 1302 | $thumb_name = $static_file_path.DIRECTORY_SEPARATOR.$image_path.DIRECTORY_SEPARATOR.$format; |
| | 1303 | $thumb->get_thumbnail($dest, $thumb_w, $thumb_h, $scale, $thumb_name, 'png'); |
| | 1304 | $basename = basename($dest); |
| 1315 | | # Get source image information |
| 1316 | | list($src_w, $src_h, $src_type, $src_attr) = getimagesize($src); |
| 1317 | | |
| 1318 | | # Load source image |
| 1319 | | $src_img; |
| 1320 | | |
| 1321 | | switch($src_type) { |
| 1322 | | case 1: #GIF |
| 1323 | | $src_img = @imagecreatefromgif($src); |
| 1324 | | break; |
| 1325 | | case 2: #JPEG |
| 1326 | | $src_img = @imagecreatefromjpeg($src); |
| 1327 | | break; |
| 1328 | | case 3: #PNG |
| 1329 | | $src_img = @imagecreatefrompng($src); |
| 1330 | | break; |
| 1331 | | default: #Unsupported format |
| 1332 | | return ''; |
| 1333 | | } |
| 1334 | | |
| 1335 | | if (!$src_img) { |
| 1336 | | return ''; |
| 1337 | | } |
| 1338 | | |
| 1339 | | # Calculate thumbnail size |
| 1340 | | $thumb_w = $src_w; |
| 1341 | | $thumb_h = $src_h; |
| 1342 | | |
| 1343 | | if ($scale > 0) { |
| 1344 | | $thumb_w = $src_w * $scale / 100; |
| 1345 | | $thumb_h = $src_h * $scale / 100; |
| 1346 | | } elseif ($width > 0 || $height > 0) { |
| 1347 | | $x = $width; if ($width > 0) $thumb_w; |
| 1348 | | $y = $height; if ($height > 0) $thumb_h; |
| 1349 | | $pct = $width > 0 ? ($x / $thumb_w) : ($y / $thumb_h); |
| 1350 | | $thumb_w = (int)($thumb_w * $pct); |
| 1351 | | $thumb_h = (int)($thumb_h * $pct); |
| 1352 | | } |
| 1353 | | |
| 1354 | | # Generate |
| 1355 | | if(!file_exists($dest)) { |
| 1356 | | $dir_name = dirname($dest); |
| 1357 | | if (!file_exists($dir_name)) { |
| 1358 | | mkpath($dir_name, 0777); |
| 1359 | | } |
| 1360 | | if (!is_writable($dir_name)) { |
| 1361 | | imagedestroy($src_img); |
| 1362 | | return ''; |
| 1363 | | } |
| 1364 | | |
| 1365 | | # Create thumbnail |
| 1366 | | $dst_img = imagecreatetruecolor ( $thumb_w, $thumb_h ); |
| 1367 | | $result = imagecopyresampled ( $dst_img, $src_img, 0, 0, 0, 0, |
| 1368 | | $thumb_w, $thumb_h, $src_w, $src_h); |
| 1369 | | |
| 1370 | | $output = $src_type; |
| 1371 | | if ($dest_type != 'auto') { |
| 1372 | | $output = strtolower($dest_type) == 'gif' ? 1 |
| 1373 | | : strtolower($dest_type) == 'jpeg' ? 2 |
| 1374 | | : strtolower($dest_type) == 'png' ? 3 |
| 1375 | | : $src_type; |
| 1376 | | } |
| 1377 | | switch($output) { |
| 1378 | | case 1: #GIF |
| 1379 | | imagegif($dst_img, $dest); |
| 1380 | | break; |
| 1381 | | case 2: #JPEG |
| 1382 | | imagejpeg($dst_img, $dest); |
| 1383 | | break; |
| 1384 | | case 3: #PNG |
| 1385 | | imagepng($dst_img, $dest); |
| 1386 | | break; |
| 1387 | | } |
| 1388 | | imagedestroy($dst_img); |
| 1389 | | } |
| 1390 | | |
| 1391 | | imagedestroy($src_img); |
| | 1315 | require_once('thumbnail_lib.php'); |
| | 1316 | $thumb = new Thumbnail($src); |
| | 1317 | |
| | 1318 | $thumb_w = $width; |
| | 1319 | $thumb_h = $height; |
| | 1320 | $thumb->get_thumbnail($dest, $thumb_w, $thumb_h, $scale, null, $dest_type); |
| 1401 | | $name_w = 'auto'; $name_h = 'auto'; |
| 1402 | | if ($width > 0) |
| 1403 | | $name_w = $width; |
| 1404 | | if ($height > 0) |
| 1405 | | $name_h = $height; |
| 1406 | | |
| 1407 | | # Generate thumbnail file name |
| 1408 | | $basename = basename($asset['asset_file_name'], '.' . $asset['asset_file_ext']); |
| 1409 | | $id = $asset['asset_id']; |
| 1410 | | $ext = '.' . $asset['asset_file_ext']; |
| 1411 | | $patterns[0] = '/%w/'; |
| 1412 | | $patterns[1] = '/%h/'; |
| 1413 | | $patterns[2] = '/%f/'; |
| 1414 | | $patterns[3] = '/%i/'; |
| 1415 | | $patterns[4] = '/%x/'; |
| 1416 | | $replacement[0] = $name_w; |
| 1417 | | $replacement[1] = $name_h; |
| 1418 | | $replacement[2] = $basename; |
| 1419 | | $replacement[3] = $id; |
| 1420 | | $replacement[4] = $ext; |
| 1421 | | $thumb_filename = preg_replace($patterns, $replacement, $format); |