mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-22 18:48:41 +00:00
refactor(web/image_hosting): use php-imagick
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
2e51c20d9f
commit
d490de8bd4
@ -6,7 +6,7 @@ ENV DEBIAN_FRONTEND=noninteractive
|
||||
RUN dpkg -s gnupg 2>/dev/null || (apt-get update && apt-get install -y gnupg) &&\
|
||||
echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu jammy main" | tee /etc/apt/sources.list.d/ondrej-php.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C &&\
|
||||
apt-get update --allow-unauthenticated &&\
|
||||
apt-get install -y --allow-unauthenticated -o Dpkg::Options::="--force-overwrite" php7.4 php7.4-yaml php7.4-xml php7.4-dev php7.4-zip php7.4-mysql php7.4-mbstring php7.4-gd libseccomp-dev git vim ntp zip unzip curl wget libapache2-mod-xsendfile mysql-server php-pear cmake fp-compiler re2c libyaml-dev python2.7 python3.10 python3-requests openjdk-8-jdk openjdk-11-jdk openjdk-17-jdk
|
||||
apt-get install -y --allow-unauthenticated -o Dpkg::Options::="--force-overwrite" php7.4 php7.4-yaml php7.4-xml php7.4-dev php7.4-zip php7.4-mysql php7.4-mbstring php7.4-gd php7.4-imagick libseccomp-dev git vim ntp zip unzip curl wget libapache2-mod-xsendfile mysql-server php-pear cmake fp-compiler re2c libyaml-dev python2.7 python3.10 python3-requests openjdk-8-jdk openjdk-11-jdk openjdk-17-jdk
|
||||
|
||||
ADD . /opt/uoj
|
||||
WORKDIR /opt/uoj
|
||||
|
@ -54,6 +54,7 @@
|
||||
|
||||
list($width, $height, $type) = $size;
|
||||
$hash = hash_file("sha256", $_FILES['image_upload_file']['tmp_name']);
|
||||
$scale = ceil($width / 750.0);
|
||||
|
||||
$watermark_text = UOJConfig::$data['profile']['oj-name-short'];
|
||||
if (isSuperUser($myUser) && $_POST['watermark'] == 'no_watermark') {
|
||||
@ -70,16 +71,17 @@
|
||||
die(json_encode(['status' => 'success', 'path' => $existing_image['path']]));
|
||||
}
|
||||
|
||||
$img = imagecreatefromstring(file_get_contents($_FILES["image_upload_file"]["tmp_name"]));
|
||||
$white = imagecolorallocatealpha($img, 255, 255, 255, 30);
|
||||
$black = imagecolorallocatealpha($img, 50, 50, 50, 70);
|
||||
$scale = ceil($width / 750.0);
|
||||
|
||||
imagettftext($img, strval($scale * 16), 0, ($scale * 16) + $scale, max(0, $height - ($scale * 16) + 5) + $scale, $black, UOJContext::documentRoot().'/fonts/roboto-mono/RobotoMono-Bold.ttf', $watermark_text);
|
||||
imagefilter($img, IMG_FILTER_GAUSSIAN_BLUR);
|
||||
imagettftext($img, strval($scale * 16), 0, ($scale * 16), max(0, $height - ($scale * 16) + 5), $white, UOJContext::documentRoot().'/fonts/roboto-mono/RobotoMono-Bold.ttf', $watermark_text);
|
||||
imagepng($img, $_FILES["image_upload_file"]["tmp_name"]);
|
||||
imagedestroy($img);
|
||||
$image = new Imagick($_FILES["image_upload_file"]["tmp_name"]);
|
||||
$draw = new ImagickDraw();
|
||||
$draw->setFont(UOJContext::documentRoot().'/fonts/roboto-mono/RobotoMono-Bold.ttf');
|
||||
$draw->setFontSize($scale * 14);
|
||||
$draw->setGravity(Imagick::GRAVITY_SOUTHEAST);
|
||||
$draw->setFillColor("rgba(100,100,100,0.5)");
|
||||
$image->annotateImage($draw, 15, 10, 0, $watermark_text);
|
||||
$draw->setFillColor("rgba(255,255,255,0.65)");
|
||||
$image->annotateImage($draw, 15 + $scale, 10 + $scale, 0, $watermark_text);
|
||||
$image->setImageFormat('png');
|
||||
$image->writeImage();
|
||||
|
||||
if (($size = filesize($_FILES["image_upload_file"]["tmp_name"])) > 5242880) { // 5 MB
|
||||
throwError('too_large');
|
||||
|
@ -20,7 +20,7 @@ getAptPackage(){
|
||||
dpkg -s gnupg 2>/dev/null || (apt-get update && apt-get install -y gnupg)
|
||||
echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu jammy main" | tee /etc/apt/sources.list.d/ondrej-php.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C
|
||||
apt-get update --allow-unauthenticated
|
||||
apt-get install -y --allow-unauthenticated -o Dpkg::Options::="--force-overwrite" php7.4 php7.4-yaml php7.4-xml php7.4-dev php7.4-zip php7.4-mysql php7.4-mbstring php7.4-gd libseccomp-dev git vim ntp zip unzip curl wget libapache2-mod-xsendfile mysql-server php-pear cmake fp-compiler re2c libyaml-dev python2.7 python3.10 python3-requests openjdk-8-jdk openjdk-11-jdk openjdk-17-jdk
|
||||
apt-get install -y --allow-unauthenticated -o Dpkg::Options::="--force-overwrite" php7.4 php7.4-yaml php7.4-xml php7.4-dev php7.4-zip php7.4-mysql php7.4-mbstring php7.4-gd php7.4-imagick libseccomp-dev git vim ntp zip unzip curl wget libapache2-mod-xsendfile mysql-server php-pear cmake fp-compiler re2c libyaml-dev python2.7 python3.10 python3-requests openjdk-8-jdk openjdk-11-jdk openjdk-17-jdk
|
||||
}
|
||||
|
||||
setLAMPConf(){
|
||||
|
Loading…
Reference in New Issue
Block a user