사이트 내 전체검색
그누보드
검색목록
[팁] ani gif 섬네일 줄이기
로빈
https://cmd.kr/gnu/733 URL이 복사되었습니다.

본문

/public_html/lib/thumbnail.lib.php (두군데 수정해야함)


    // Animated GIF는 썸네일 생성하지 않음
    if($file_ext === 'gif') {
        if(is_animated_gif($source_file)) {
include_once G5_PATH."/extend/_ar.thumbnail_gif.php";
return ar_thumbnail_gifani($filename, $source_path, $target_path, $thumb_width, $thumb_height);
return basename($source_file);
}
    } else if ($file_ext === 'webp') {



            $is_animated = false;

//2022-08-16 김성대
if($file_ext === 'gif' && is_animated_gif($source_file)) {
include_once G5_PATH."/extend/_ar.thumbnail_gif.php";
return ar_thumbnail_gifani($filename, $source_path, $target_path, $thumb_width, $thumb_height);
}





/public_html/extend/_ar.thumbnail_gif.php

<?php
include_once('./_common.php');

/*
gif ani 파일을 줄이는 함수
/lib/thumbnail.lib.php의 내용에서  다음의 윗부분에 삽입

삽입내용

//2022-08-16 김성대
// 썸네일 생성
if(1||!$is_animated)
$thumb_file = thumbnail($filename, $filepath, $filepath, $thumb_width, $thumb_height, false);
else
$thumb_file = $filename;


    if($file_ext === 'gif' && is_animated_gif($source_file)) {
include_once G5_PATH."/extend/_ar.thumbnail_gif.php";
return ar_thumbnail_gifani($filename, $source_path, $target_path, $thumb_width, $thumb_height);
    }


if($file_ext === 'gif') {
        if(is_animated_gif($source_file))
            return basename($source_file);
    } else if ($file_ext === 'webp') {


include_once G5_PATH."/extend/_ar.thumbnail_gif.php";
return ar_thumbnail_gifani($filename, $source_path, $target_path, $thumb_width, $thumb_height);
echo $source_file;
            echo $_SERVER['REMOTE_ADDR'],basename($source_file);
            return basename($source_file);
}
    }
*/

function ar_thumbnail_gifani($filename, $source_path, $target_path, $thumb_width, $thumb_height) {
$source_file=$source_path.'/'.$filename;
$thumb_filename = preg_replace("/\.[^\.]+$/i", "", $filename); // 확장자제거
$thumb_file = "$target_path/thumb-{$thumb_filename}_{$thumb_width}x{$thumb_height}.gif";
//echo __LINE__,"<BR>";
if (!is_file($source_file) || filesize($source_file)<100) return '';
//echo __LINE__,"<BR>";
if (filesize($source_file)<50*1024) return ''; //50k 미만이면 무시
//echo $thumb_file,"<BR>";
if (is_file($thumb_file)) {
//echo $source_file,"<BR>";
//echo $thumb_file,"<BR>";
if (filemtime($source_file)<=filemtime($thumb_file)+60) {
return basename($thumb_file);
}
@unlink($thumb_file);
}
//echo __LINE__,"<BR>";

$image = new Imagick($source_file);
$format = $image->getImageFormat();
if ($format != 'GIF') return '';

$filesize = $image->getImageSize();
$size = $image->getImageGeometry();

$size = $image->getImageGeometry();


$width = $size['width'];
$height = $size['height'];
if($width > $height){
$newHeight = $thumb_height;
$newWidth = ($thumb_width / $thumb_height) * $thumb_width ;
}else{
$newWidth = $thumb_width;
$newHeight = ($thumb_width / $width) * $thumb_height;
}

//var_dump($size);

    $crop_w = $thumb_width;
    $crop_h = $thumb_height;
    $ratio = $crop_h / $crop_w;
//echo " $ratio = $crop_h / $crop_w; <BR>";
if ($ratio<0) $ratio=1;


if( ($size['height'] / $size['width']) >= $ratio) {
$src_h = round($src_w * $ratio);
$crop_y = round(($size['height'] - $src_h) / 2);
} else {
$src_w = round($size['height'] / $ratio);
$crop_x = round(($size['width'] - $src_w) / 2);
}

//print_r($size);

//$thumb_width=$image->getImageWidth();
//$thumb_height=$image->getImageHeight();
//echo $image->getImageWidth()."x".$image->getImageHeight();

$image = $image->coalesceImages();
$new_image = new Imagick();

$totalFrames = $image->getNumberImages();
$totalFrames_count=intval($totalFrames/5);
if ($totalFrames_count<1) $totalFrames_count=1;
//echo "totalFrames :$totalFrames <BR>";

$count=0;

$image = $image->coalesceImages();

//$new_image->setImageTicksPerSecond(50);
$delay=0;



foreach ($image as $frame) {
$delay += $frame->getImageDelay();
if ($count++%$totalFrames_count==0) {
//$frame->cropImage($crop_w, $crop_h, $crop_x, $crop_y);

$frame->resizeImage($newWidth,$newHeight, imagick::FILTER_LANCZOS, 0.9, true);
$frame->cropImage ($thumb_width,$thumb_height,1,1);

//$frame->thumbnailImage($thumb_width, $thumb_height,true,true);
//$frame->setImagePage($thumb_width, $thumb_height, 0, 0);
//$frame->resizeImage($thumb_width, $thumb_height, Imagick::FILTER_BOX, 1);
$new_image->addImage($frame->getImage());
$new_image->setImageDelay($delay);
$delay=0;
}
}
$new_image = $new_image->deconstructImages();
$new_image->writeImages($thumb_file, true);
$new_image->clear();
$new_image->destroy();
if (!is_file($thumb_file) || filesize($thumb_file)<100) {
@unlink($thumb_file);
return '';
}
//echo __LINE__," $thumb_file<BR>";
//현재시간으로 설정함
@chmod($thumb_file, G5_FILE_PERMISSION);
@touch($thumb_file,filemtime($source_file));
return basename($thumb_file);
}

첨부파일

댓글목록

등록된 댓글이 없습니다.

그누보드
65 (1/2P)

Search

Copyright © Cmd 명령어 3.136.19.203