{picLeft, picRight, picTop, picBottom} = If( 1, picURL = "
https://upload.wikimedia.org/wikipedia/commons/1/1e/Rooster_-_Public_Domain.jpg"; // Lisafern, CC0, via Wikimedia Commons --
https://commons.wikimedia.org/wiki/Special:ListFiles/lisafern {600000, 6000000, 35, 5};// , // picURL = "
https://upload.wikimedia.org/wikipedia/commons/3/3a/Foster_graph_hamiltonian.png"; // public domain:
https://commons.wikimedia.org/wiki/File:Foster_graph_hamiltonian.png {450000, 10000000, 32, 8};// ); gTempFiles = Convert File Path( "$temp\pil_webp\", "windows" ); Delete Directory( gTempFiles ); // 주의! Create Directory( gTempFiles ); // 디렉터리가 존재하고 비어 있습니다. // Python을 로드하고 PIL이 사용 가능한지 확인합니다. rc = Python Execute( {}, {}, "\[from PIL import Image, ImageSequence import numpy as np import os import time def rmse(imageA, imageB): if imageA.size != imageB.size: raise ValueError("RMSE를 계산하려면 이미지의 크기가 같아야 합니다.") imgA_np = np.asarray(imageA).astype("float") imgB_np = np.asarray(imageB).astype("float") err = np.sum((imgA_np - imgB_np) ** 2) err /= float(imageA.size[0] * imageA.size[1]) return np.sqrt(err) ]\", echo( 0 ) ); If( rc != 0, Throw( "python init error rc=" || Char( rc ) ), "ok" ); // .webp, .jpg, .gif 파일 목록에 JSL 이미지를 추가합니다. addNewFrame = Function( {filename, img}, img << saveimage( gTempFiles || filename || ".png", "png" ); // png는 무손실 포맷이며 rmse는 이를 비교에 사용합니다. File Size( gTempFiles || filename || ".png" ); ); // saveFrameTo... 및 saveFramesTo... 함수는 // 일반적으로 포맷이 사용되는 방식을 반영합니다. // 일반적으로 단일 프레임 GIF를 만들지는 않으며 // 다중 프레임 JPG는 사실상 만들 수 없습니다. saveFrameToWebP = Function( {outputfilename, qual}, {filelist, webpname, rc}, // filelist = Transform Each( {f}, Files In Directory( gTempFiles ), // Convert File Path( gTempFiles || f, "windows" );// ); If( N Items( filelist ) != 1, // Throw( "saveFrameToWebP nitems=" || Char( N Items( filelist ) ) );// ); webpname = Convert File Path( outputfilename, "windows" ); rc = Python Execute( {filelist, webpname, qual}, // inputs {_rmse, _ossize, _timew, _timer}, // outputs "\[#
https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#webp imgs = [] for f in filelist: imgs.append(Image.open(f).convert('RGB')) img=imgs[0] _timew = time.perf_counter() img.save(webpname,save_all=True,format="WEBP", minimize_size=True, lossless=False,quality=int(qual)) _timew = time.perf_counter() - _timew _timer = time.perf_counter() ir = Image.open(webpname).convert('RGB') _timer = time.perf_counter() - _timer _rmse = rmse(img,ir) _ossize = os.path.getsize(webpname) imgs = None ]\", echo( 0 ) ); If( rc != 0, // Throw( "saveFrameToWebP 오류 rc=" || Char( rc ) );// , // 평가 List( {_rmse, _ossize, _timew, _timer} );// 반환 값 ); ); saveFrameToPng = Function( {outputfilename, qual}, {filelist, pngname, rc}, // filelist = Transform Each( {f}, Files In Directory( gTempFiles ), // Convert File Path( gTempFiles || f, "windows" );// ); If( N Items( filelist ) != 1, // Throw( "saveFrameToPng nitems=" || Char( N Items( filelist ) ) );// ); pngname = Convert File Path( outputfilename, "windows" ); rc = Python Execute( {filelist, pngname, qual}, // inputs {_rmse, _ossize, _timew, _timer}, // outputs "\[# imgs = [] for f in filelist: imgs.append(Image.open(f).convert('RGB')) img=imgs[0] _timew = time.perf_counter() img.save(pngname, save_all=True, format="PNG", optimize=True, quality=int(qual)) _timew = time.perf_counter() - _timew _timer = time.perf_counter() ir = Image.open(pngname).convert('RGB') _timer = time.perf_counter() - _timer _rmse = rmse(img, ir) _ossize = os.path.getsize(pngname) imgs = None ]\", echo( 0 ) ); If( rc != 0, // Throw( "saveFrameToWebP 오류 rc=" || Char( rc ) );// , // Eval List( {_rmse, _ossize, _timew, _timer} );// 반환 값 ); ); saveFrameToJPG = Function( {outputfilename, qual}, {filelist, jpgname, rc}, // filelist = Transform Each( {f}, Files In Directory( gTempFiles ), // Convert File Path( gTempFiles || f, "windows" );// ); If( N Items( filelist ) != 1, // Throw( "saveFrameToJPG nitems=" || Char( N Items( filelist ) ) );// ); jpgname = Convert File Path( outputfilename, "windows" ); rc = Python Execute( {filelist, jpgname, qual}, // inputs {_rmse, _ossize, _timew, _timer}, // outputs "\[#
https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#webp imgs = [] for f in filelist: imgs.append(Image.open(f).convert('RGB')) img=imgs[0] _timew = time.perf_counter() img.save(jpgname,format="JPEG", optimize=True, quality=int(qual)) _timew = time.perf_counter() - _timew _timer = time.perf_counter() ir = Image.open(jpgname).convert('RGB') _timer = time.perf_counter() - _timer _rmse = rmse(img,ir) _ossize = os.path.getsize(jpgname) imgs = None ]\", echo( 0 ) ); If( rc != 0, // Throw( "saveFrameToJPG 오류 rc=" || Char( rc ) );// , // Eval List( {_rmse, _ossize, _timew, _timer} );// 반환 값 ); ); // Lisafern, CC0, Wikimedia Commons 제공 --
https://commons.wikimedia.org/wiki/Special:ListFiles/lisafern img = New Image( picURL ); start = HP Time(); pngSize1 = addNewFrame( "1jsl.png", img ); JSLpngTime = (HP Time() - start) / 1e6; dt = New Table( // New Column( "extension", "character" ), New Column( "size" ), New Column( "timewrite" ), New Column( "timeread" ), New Column( "rmse" ) ); dt << addrows( 1 ); extension = "JSLPng"; size = pngSize1; rmse = 0; timewrite = JSLpngTime; dt << addrows( 1 ); extension = "PILPng"; {rmse, size, timewrite, timeread} = saveFrameToPng( "$temp/1.png", 95 ); For( i = 0, i <= 100, i += 1, dt << addrows( 1 ); extension = "WebP"; {rmse, size, timewrite, timeread} = saveFrameToWebP( "$temp/1.webp", i ); Wait( .01 ); dt << addrows( 1 ); extension = "Jpg"; {rmse, size, timewrite, timeread} = saveFrameToJpg( "$temp/1.jpg", i ); Wait( .01 ); ); dt << 그래프 빌더( 크기( 996, 713 ), 제어판 표시( 0 ), 범례 위치( "부유 영역 내부" ), 변수( X( :size ), Y( :rmse ), 오버레이( :extension ), 크기( :timewrite ) ), 요소( 점( X, Y, 범례( 47 ) ) ), 보고서 전송( 디스패치( {}, "size", 스케일 박스, {스케일( "로그" ), 형식( "엔지니어링 SI", 12 ), 최소값( 1e4 ), 최대값( 6.1e6 ), 보조 눈금( 1 ), 레이블 행( {주요 그리드 표시( 1 ), 보조 그리드 표시( 1 ), 보조 레이블 표시( 1 )} )} ), 디스패치( {}, "rmse", 스케일 박스, {최소값( -0.5 ), 최대값( 32 ), 증가( 5 ), 보조 Ticks( 0 )} ), Dispatch( {}, "400", ScaleBox, {Legend Model( 47, Type Properties( 0, "Marker", {Marker( "FilledCircle" )} ), Properties( 1, {Line Color( 3 ), Marker( "FilledCircle" )}, Item ID( "Jpg", 1 ) ), Properties( 2, {Line Color( 5 ), Marker( "FilledCircle" )}, Item ID( "JSLPng", 1 ) ), Properties( 3, {Line Color( 6 ), Marker( "FilledCircle" )}, Item ID( "PILPng", 1 ) ), Properties( 4, {Line Color( 8 ), Marker( "FilledCircle" )}, Item ID( "WebP", 1 ) ), Properties( -1, {Marker( "FilledSquare" )}, 항목 ID( "Png", 1 ) ) )} ), Dispatch( {}, "그래프 제목", TextEditBox, {Set Text( "WebP vs Jpg vs Png" )} ), Dispatch( {}, "크기", TextEditBox, {Set Text( "디스크 크기, 바이트" )} ), Dispatch( {}, "rmse", TextEditBox, {Set Text( "RMSE out of 255" )} ), Dispatch( {}, "그래프 빌더", FrameBox, {마커 그리기 모드( "일반" ), 참조선 순서( 6 ), 이미지 추가( 2, // 그리드 선 위 레이어 2 이미지( 새 이미지( picURL ) ), 경계( 왼쪽( picLeft ), 오른쪽( picRight ), 위쪽( picTop ), 아래쪽( picBottom ) ) ), 그래픽 스크립트 추가( 7, 설명( "" ), Empty() )} ), Dispatch( {}, "400", LegendBox, {Legend Position( {47, [4, 0, 3, 2, 1]} )} ) ) ); dt << Graph Builder( Size( 638, 370 ), Show Control Panel( 0 ), Variables( X( :size ), Y( :timeread ), Overlay( :extension ) ), Elements( Points( X, Y, Legend( 9 ) ) ), SendToReport( Dispatch( {}, "400", ScaleBox, {Legend Model( 9, Properties( 0, {Line Color( 3 )}, Item ID( "Jpg", 1 ) ), Properties( 1, {Line Color( 5 )}, Item ID( "JSLPng", 1 ) ), Properties( 2, {Line Color( 6 )}, Item ID( "PILPng", 1 ) ), Properties( 3, {Line Color( 8 )}, Item ID( "WebP", 1 ) ) )} ), Dispatch( {}, "400", 범례 상자, {범례 위치( {9, [0, 3, 2, 1]} )} ) ) );