function addWatermark($srcPath, $dstPath, $width, $height) { global $IP, $wgImageMagickConvertCommand, $wgImageMagickCompositeCommand; // do not add a watermark if the image is too small if (WatermarkSupport::validImageSize($width, $height) == false) { return; } $wm = $IP . '/skins/WikiHow/images/watermark.svg'; $watermarkWidth = 1074.447; $targetWidth = $width / 8; $density = 72 * $targetWidth / $watermarkWidth; // we have a lower limit on density so the watermark is readable if ($density < 4.0) { $density = 4.0; } $cmd = ""; // make sure image is rgb format so the watermark applies correctly if (WatermarkSupport::isCMYK($srcPath)) { $cmd = wfEscapeShellArg($wgImageMagickConvertCommand) . " " . wfEscapeShellArg($srcPath) . " " . "-colorspace RGB " . wfEscapeShellArg($dstPath) . ";"; $srcPath = $dstPath; } $cmd = $cmd . wfEscapeShellArg($wgImageMagickConvertCommand) . " -density {$density} -background none " . wfEscapeShellArg($wm) . " miff:- | " . wfEscapeShellArg($wgImageMagickCompositeCommand) . " -gravity southeast -quality 100 -geometry +8+10 - " . wfEscapeShellArg($srcPath) . " " . wfEscapeShellArg($dstPath) . " 2>&1"; $beforeExists = file_exists($dstPath); wfDebug(__METHOD__ . ": running ImageMagick: {$cmd}\n"); $err = wfShellExec($cmd, $retval); $afterExists = file_exists($dstPath); $currentDate = `date`; wfErrorLog(trim($currentDate) . " {$cmd} b:" . ($beforeExists ? 't' : 'f') . " a:" . ($afterExists ? 't' : 'f') . "\n", '/tmp/watermark.log'); wfProfileOut('watermark'); }
static function onImageConvertNoScale($image, $params) { // edge case...if the image will not actually get watermarked because it's too small, just return true if (WatermarkSupport::validImageSize($params['physicalWidth'], $params['physicalHeight']) == false) { return true; } // return false here..we want to create the watermarked file! // AG - TODO trying to figure out why we check if the file exists here..doesn't // seem necessary or should be inverted if (isset($params[WatermarkSupport::ADD_WATERMARK]) && $params[WatermarkSupport::ADD_WATERMARK] || $image->getRepo()->fileExists($params['dstPath'])) { return false; } return true; }
function wfImageConvertNoScale($dstPath, $params) { // edge case...if the image will not actually get watermarked because it's too small, just return true if (WatermarkSupport::validImageSize($params['physicalWidth'], $params['physicalHeight']) == false) { return true; } // return false here..we want to create the watemarked file! if ($params[WatermarkSupport::ADD_WATERMARK] || file_exists($dstPath)) { return false; } return true; }