움직이는 webp 이미지 업로드 가능하도록 수정중

This commit is contained in:
kagla
2021-06-25 14:03:45 +09:00
parent 8ac1d25242
commit bd33a31a10
3 changed files with 21 additions and 13 deletions

View File

@ -85,7 +85,7 @@ function get_file_thumbnail($file){
if( ! is_array($file) ) return '';
if( preg_match('/(\.jpg|\.jpeg|\.gif|\.png|\.bmp)$/i', $file['file']) && $contents = run_replace('get_file_thumbnail_tags', '', $file) ){
if( preg_match('/(\.jpg|\.jpeg|\.gif|\.png|\.bmp|\.webp)$/i', $file['file']) && $contents = run_replace('get_file_thumbnail_tags', '', $file) ){
return $contents;
} else if ($file['view']) {
return get_view_thumbnail($file['view']);
@ -108,6 +108,8 @@ function get_view_thumbnail($contents, $thumb_width=0)
if(empty($matches))
return $contents;
// $extensions = array(1=>'gif', 2=>'jpg', 3=>'png', 18=>'webp');
for($i=0; $i<count($matches[1]); $i++) {
$img = $matches[1][$i];
@ -138,8 +140,12 @@ function get_view_thumbnail($contents, $thumb_width=0)
if(empty($size))
continue;
// $file_ext = $extensions[$size[2]];
$file_ext = G5_IMAGE_EXTENSIONS[$size[2]];
if (!$file_ext) continue;
// jpg 이면 exif 체크
if($size[2] == 2 && function_exists('exif_read_data')) {
if( $file_ext === 'jpg' && function_exists('exif_read_data')) {
$degree = 0;
$exif = @exif_read_data($srcfile);
if(!empty($exif['Orientation'])) {
@ -166,7 +172,7 @@ function get_view_thumbnail($contents, $thumb_width=0)
// Animated GIF 체크
$is_animated = false;
if($size[2] == 1) {
if($file_ext === 'gif') {
$is_animated = is_animated_gif($srcfile);
if($replace_content = run_replace('thumbnail_is_animated_gif_content', '', $contents, $srcfile, $is_animated, $img_tag, $data_path, $size)){
@ -229,16 +235,18 @@ function thumbnail($filename, $source_path, $target_path, $thumb_width, $thumb_h
$size = @getimagesize($source_file);
$extensions = array(1 => 'gif', 2 => 'jpg', 3 => 'png', 18 => 'webp');
$file_ext = $extensions[$size[2]]; // 파일 확장자
// $extensions = array(1 => 'gif', 2 => 'jpg', 3 => 'png', 18 => 'webp');
// $file_ext = $extensions[$size[2]]; // 파일 확장자
$file_ext = G5_IMAGE_EXTENSIONS[$size[2]];
if (!$file_ext) return;
// gif, jpg, png, webp 에 대해서만 적용
// if ( !(isset($size[2]) && ($size[2] == 1 || $size[2] == 2 || $size[2] == 3 || $size[2] == 18)) )
// return;
// $extensions 배열에 없는 확장자 라면 썸네일 만들지 않음
if (!in_array($file_ext, $extensions))
return;
// if (!in_array($file_ext, $extensions))
// return;
if (!is_dir($target_path)) {
@mkdir($target_path, G5_DIR_PERMISSION);

View File

@ -55,13 +55,13 @@
<!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
<script src="./js/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="./swfupload/swfupload.js"></script>
<script type="text/javascript" src="./swfupload/jquery.swfupload.js"></script>
<script type="text/javascript" src="./swfupload/swfupload.js?v=210625-1329"></script>
<script type="text/javascript" src="./swfupload/jquery.swfupload.js?v=210625-1329"></script>
<!-- The basic File Upload plugin -->
<script src="./js/jquery.fileupload.js?v=140715"></script>
<script src="./js/jquery.fileupload.js?v=210625-1329"></script>
<script src="./js/basic.js?v3"></script>
<script src="./js/basic.js?v=210625-1329"></script>
</body>
</html>

View File

@ -1092,7 +1092,7 @@ class UploadHandler
//throw new Exception("Invalid image MIME type");
return false;
}
$image_from_file = self::$MIME_TYPES_PROCESSORS[$mime_type][0];
$image_to_file = self::$MIME_TYPES_PROCESSORS[$mime_type][1];
@ -1101,7 +1101,7 @@ class UploadHandler
// https://stackoverflow.com/questions/61394477/php-e-error-gd-webp-cannot-allocate-temporary-buffer
// 움직이는 webp 이미지나 큰사이즈의 webp 이미지에 대한 해결 방안은 아직 없는 것 같다
$reprocessed_image = @$image_from_file($file_path);
// error_log("\$image_from_file = '$image_from_file', \$image_to_file = '$image_to_file', \$reprocessed_image = '$reprocessed_image' ");
// error_log("\$image_from_file = '$image_from_file', \$image_to_file = '$image_to_file', \$reprocessed_image = '$reprocessed_image', \$file_path ='$file_path' ");
if (!$reprocessed_image) {
//throw new Exception("Unable to create reprocessed image from file");