Resize images upon upload in Mediawiki

孤人 提交于 2019-12-10 03:44:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!