Exemple #1
0
 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');
 }
    if (!$articleTitle) {
        continue;
    }
    $articleName = $articleTitle->getPartialURL();
    echo "processing article: {$articleName} with id: {$articleId}\n";
    $processedCount = $processedCount + 1;
    $articleName = $articleTitle->getPartialURL();
    $imageLinks = array();
    $res = $dbr->select(array('imagelinks'), 'il_to', array('il_from' => $articleId));
    $found = "";
    foreach ($res as $row) {
        $title = Title::newFromText($row->il_to, NS_IMAGE);
        $imageFile = wfFindFile($title, false);
        if ($imageFile && $imageFile->fileExists) {
            // make sure it's a wikiphoto image
            if ($imageFile->user_text != "Wikiphoto") {
                continue;
            }
            $fullPath = $imageFile->getFullPath();
            //decho("checking", $fullPath, false);
            $cmyk = WatermarkSupport::isCMYK($fullPath);
            if ($cmyk) {
                $found = $fullPath;
                break;
            }
        }
    }
    if ($found != "") {
        echo "article with CMYK image: {$articleId} - {$articleName} image is: {$found}\n";
    }
}