问题
I am ideally after resizing and setting a maxWidth and maxHeight on all my image uploads to mediawiki.
Having looked through the documentation of various different pages in mediawiki I am unable to find anything that says you can edit in anyway images uploaded to a site built on mediaWiki
I have no problem in writing some custom PHP but truth is I have no idea where to start looking in mediaWiki.
My thoughts are: imagemagick similarly to this:
I think you need the > flag on the resize: convert -size 300x200 xc:red small.png convert -size 1000x500 xc:blue large.png Now convert them both to 800x600 with no flags: convert small.png -resize 800x600 a.png # 800x533 convert large.png -resize 800x600 b.png # 800x400 Now with flags: convert small.png -resize 800x600\> a.png # 300x200 convert large.png -resize 800x600\> b.png # 800x400
But again, I cannot see where you would run this after an image upload to change the files dimensions.
Any help would be fantastic.
回答1:
You can try with an extension properly hooked : https://www.mediawiki.org/wiki/Manual:Hooks/UploadForm:BeforeProcessing or https://www.mediawiki.org/wiki/Manual:Hooks/UploadVerifyFile
Edit :
this example to put at the end of LocalSettings.php add a logo in the upper right corner of uploaded files :
$wgHooks['UploadForm:BeforeProcessing'][]=function(&$upload) {
$fictmp = $upload->mUpload->getTempPath();
$newtmp = tempnam("/tmp", "tmp");
$mylogo = "/path/to/my/logo/220px-SNice.svg.png";
exec("composite -gravity NorthEast $mylogo $fictmp $newtmp" );
copy($newtmp, $fictmp);
unlink($newtmp);
return true;
};
来源:https://stackoverflow.com/questions/54655194/resize-images-upon-upload-in-mediawiki