@@ -115,13 +115,26 @@ public function convert($type = 'string', $convert_path = 'null->null', $source
115
115
// Select a converter.
116
116
$ engines = $ this ->getEngines ($ convert_path );
117
117
118
+ // Remember the file stats of the source file.
119
+ $ file_stat = NULL ;
120
+ if ($ type === 'file ' && is_file ($ source )) {
121
+ $ file_stat = stat ($ source );
122
+ }
123
+
118
124
// Attempt to convert the file.
119
125
$ errors = array ();
120
126
foreach ($ engines as $ engine ) {
121
127
try {
122
128
$ engine ->$ convert ($ source , $ destination );
123
129
$ this ->previous_engines [] = $ engine ;
124
130
$ return ();
131
+
132
+ // Preserve the same owner/mode as the source.
133
+ if ($ type === 'file ' && is_file ($ destination ) && isset ($ file_stat )) {
134
+ chown ($ destination , $ file_stat ['uid ' ]);
135
+ chgrp ($ destination , $ file_stat ['gid ' ]);
136
+ chmod ($ destination , $ file_stat ['mode ' ]);
137
+ }
125
138
return $ this ;
126
139
} catch (\Exception $ e ) {
127
140
$ errors [] = $ e ->getMessage ();
@@ -287,13 +300,7 @@ public function optimizeFile($source = NULL, $destination = NULL, $ext = NULL) {
287
300
if (!isset ($ destination )) {
288
301
$ destination = $ source ;
289
302
}
290
- $ engines = $ this ->getEngines ("$ ext-> $ ext " );
291
- foreach ($ engines as $ engine ) {
292
- if ($ engine ->convertFile ($ source , $ destination )) {
293
- return $ this ;
294
- }
295
- }
296
- return $ this ;
303
+ return $ this ->convert ('file ' , "$ ext-> $ ext " , $ source , $ destination );
297
304
}
298
305
299
306
public function &setConverter ($ convert_path = 'null->null ' , $ configuration = 'null:default ' ) {
0 commit comments