+function resizeImage ( $srcpath, $x1, $y1, $x2, $y2) {
+ global $wgUseImageMagick, $wgImageMagickConvertCommand;
+ global $wgCustomConvertCommand;
+ global $wgTmpDirectory;
+
+ # generate width and height
+ $w = abs($x2 - $x1);
+ $h = abs($y2 - $y1);
+
+ # create temporary destination file location
+ $dstpath = tempnam($wgTmpDirectory, "EditImage");
+
+ # specify white background color, will be used for transparent images
+ # in internet explorer/windows instead of default black.
+ $cmd = wfescapeshellarg($wgImageMagickConvertCommand) .
+ " -background white " .
+ wfescapeshellarg($srcpath) .
+ // coalesce is needed to scale animated gifs properly (bug 1017).
+ ' -coalesce ' .
+ " -crop {$w}x{$h}+$x1+$y1! " .
+ wfescapeshellarg($dstpath) . " 2>&1";
+ wfDebug( __METHOD__.": running ImageMagick: $cmd\n");
+ wfProfileIn( 'convert' );
+ $err = wfShellExec( $cmd, $retval );
+ wfProfileOut( 'convert' );
+ return($dstpath);
+}
+
+function uploadNewFile ($old_file, $new_filename) {
+ global $wgRequest;
+ $form = new UploadForm($wgRequest);
+
+ $form->mTempPath = $new_filename;
+ $form->mSrcName = $old_file->getName();
+ $form->mFileSize = filesize($new_filename);
+ $form->mSessionKey = false;
+ $form->mStashed = false;
+ $form->mUploadClicked = true;
+
+ $form->execute();