4545
4646 // (re)generate
4747 if ( ($ data ['cachet ' ] < $ data ['mtime ' ]) || ($ data ['cachet ' ] < $ data ['selft ' ]) ){
48- tile_gd ($ data );
48+ if ($ conf ['im_convert ' ]){
49+ tile_im ($ data );
50+ }else {
51+ tile_gd ($ data );
52+ }
4953 }
5054
5155 // send
6165
6266
6367function tile_gd ($ d ){
68+ global $ conf ;
69+
6470 $ img = null ;
6571 if (preg_match ('/\.jpe?g$/ ' ,$ d ['file ' ])){
6672 $ img = @imagecreatefromjpeg ($ d ['file ' ]);
@@ -77,10 +83,33 @@ function tile_gd($d){
7783 $ scale = image_scale ($ crop ,abs ($ d ['brx ' ] - $ d ['tlx ' ]),abs ($ d ['bry ' ] - $ d ['tly ' ]),$ d ['ts ' ],$ d ['ts ' ]);
7884 imagedestroy ($ crop );
7985
80- imagejpeg ($ scale ,$ d ['cache ' ]);
86+ imagejpeg ($ scale ,$ d ['cache ' ], $ conf [ ' jpg_quality ' ] );
8187 imagedestroy ($ scale );
88+
89+ if ($ conf ['fperm ' ]) chmod ($ d ['cache ' ], $ conf ['fperm ' ]);
8290}
8391
92+ function tile_im ($ d ){
93+ global $ conf ;
94+
95+ $ cmd = $ conf ['im_convert ' ];
96+ $ cmd .= ' ' .escapeshellarg ($ d ['file ' ]);
97+ $ cmd .= ' -crop ' .abs ($ d ['brx ' ] - $ d ['tlx ' ]).'x ' .abs ($ d ['bry ' ] - $ d ['tly ' ]).'!+ ' .$ d ['tlx ' ].'+ ' .$ d ['tly ' ];
98+
99+ $ cmd .= ' -resize ' .$ d ['ts ' ].'x ' .$ d ['ts ' ].'! ' ;
100+
101+ $ cmd .= ' -quality ' .$ conf ['jpg_quality ' ];
102+ $ cmd .= ' ' .escapeshellarg ($ d ['cache ' ]);
103+
104+ #dbg($cmd); exit;
105+
106+ @exec ($ cmd ,$ out ,$ retval );
107+ if ($ retval == 0 ) return true ;
108+ gfx_error ('generic ' );
109+ }
110+
111+
112+
84113function image_scale ($ image ,$ x ,$ y ,$ w ,$ h ){
85114 $ scale =imagecreatetruecolor ($ w ,$ h );
86115 imagecopyresampled ($ scale ,$ image ,0 ,0 ,0 ,0 ,$ w ,$ h ,$ x ,$ y );
0 commit comments