테스트 사이트 - 개발 중인 베타 버전입니다

스마트에디터5 이미지 (png 압축 수준) 채택완료

아이소크 2년 전 조회 1,906

사이트 특성상 png파일들이 많이 올라올 것 같은데 압축률을 9로 설정해도 파일용량은 크게 줄어들지를 않네요.

 

png파일의 압축률을 9 이상으로 더 압축하는 방법이 있을까요? 이게 불가능하다면 png파일은 jpg파일로 변경하여 더 적은 용량을 갖도록 하는 방법이 있을까요?

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트
2년 전

</p>

<p>/**

 * 

 * @param string $importPath

 * @param string $exportPath

 * @param int $quality       0 = low / smaller file, 100 = better / bigger file </p>

<p> * @throws Exception

 * @return boolean

 */

function png2jpg($importPath, $exportPath = null, $quality = 50) {

    $rtn = true;</p>

<p> </p>

<p>    try {

        $arr = [];</p>

<p> </p>

<p>        $image = imagecreatefrompng($importPath);

        $bg = imagecreatetruecolor(imagesx($image), imagesy($image));</p>

<p> </p>

<p>        $arr[] = $image;

        $arr[] = $bg;

        $arr[] = imagefill($bg, 0, 0, imagecolorallocate($bg, 255, 255, 255));

        $arr[] = imagealphablending($bg, TRUE);

        $arr[] = imagecopy($bg, $image, 0, 0, 0, 0, imagesx($image), imagesy($image));

        $arr[] = imagedestroy($image);</p>

<p> </p>

<p>        $result = $importPath . '.jpg';

        if (empty($exportPath) == true) {

            $result = $exportPath;

        }

        $arr[] = imagejpeg($bg, $result, $quality);

        $arr[] = imagedestroy($bg);</p>

<p> </p>

<p>        foreach ($arr as $v) {

            if ($v === false) {

                $rtn = false;

                break;

            }

        }

    } catch (Exception $err) {

        $rtn = false;

        throw $err;

    }</p>

<p> </p>

<p>    return $rtn;

}</p>

<p>

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

아이소크
2년 전
베르만님 감사합니다. 혹시 해당 소스를 어떤 파일에 집어넣어야 할까요?

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인