• Resuelto sguzgon

    (@sguzgon)


    Buenas noches,

    Me dirijo a ustedes para plantearles mi duda. Estoy intentando asignar una marca de agua a las imágenes contenidas en /uploads, en localhost funciona bien, pero lo he subido a mi servidor y no consigo hacerlo funcionar. A continuación el código que uso:

    .htaccess

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteRule (.*)wp-content/uploads $1watermark.php?p=br&q=90&src=wp-content/uploads/$2
    </IfModule>

    watermark.php

    <?php
    //we tell the server to treat this file as if it wore an image
    header('Content-type: image/jpeg');
    //image file path
    $img = $_GET['src'];
    //watermark position
    $p = $_GET['p']; if(!$p) $p = 'br';
    /*
    p can be anything from the following list:
    tl = top left
    tc = top center
    tr = top right
    cl = center left
    c = center of the image
    cr = center right
    bl = bottom left
    bc = bottom center
    br = bottom right
    */
    //watermarked image quality
    $q = $_GET['q'];
    //if the quality field is missing or is not on the 0 to 100 scale then we set the quality to 93
    if(!$q || $q<0 || $q>100) $q = '93';
    $filetype = substr($img,strlen($img)-4,4);
    $filetype = strtolower($filetype);
    if($filetype == ".gif") $image = @imagecreatefromgif($img);
    if($filetype == ".jpg") $image = @imagecreatefromjpeg($img);
    if($filetype == ".png") $image = @imagecreatefrompng($img);
    if (!$image) die();
    //getting the image size for the original image
    $img_w = imagesx($image);
    $img_h = imagesy($image);
    
    //if the filename has 150x150 in it's name then we don't apply the watermark
    if (eregi("150x150", $img)) {
        imagejpeg($image, null, $q); die();
    } else {
        $watermark = @imagecreatefrompng('watermark.png');
    }
    /*
    //if you want to use the watermark only on bigger images then use this instead of the condition above
    if ($img_w < "150") {//if image width is less then 150 pixels
        imagejpeg($image, null, $q); die();
    } else {
        $watermark = @imagecreatefrompng('watermark.png');
    }
    */
    //getting the image size for the watermark
    $w_w = imagesx($watermark);
    $w_h = imagesy($watermark);
    if($p == "tl") {
        $dest_x = 0;
        $dest_y = 0;
    } elseif ($p == "tc") {
        $dest_x = ($img_w - $w_w)/2;
        $dest_y = 0;
    } elseif ($p == "tr") {
        $dest_x = $img_w - $w_w;
        $dest_y = 0;
    } elseif ($p == "cl") {
        $dest_x = 0;
        $dest_y = ($img_h - $w_h)/2;
    } elseif ($p == "c") {
        $dest_x = ($img_w - $w_w)/2;
        $dest_y = ($img_h - $w_h)/2;
    } elseif ($p == "cr") {
        $dest_x = $img_w - $w_w;
        $dest_y = ($img_h - $w_h)/2;
    } elseif ($p == "bl") {
        $dest_x = 0;
        $dest_y = $img_h - $w_h;
    } elseif ($p == "bc") {
        $dest_x = ($img_w - $w_w)/2;
        $dest_y = $img_h - $w_h;
    } elseif ($p == "br") {
        $dest_x = $img_w - $w_w;
        $dest_y = $img_h - $w_h;
    }
    imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $w_w, $w_h);
    imagejpeg($image, null, $q);
    imagedestroy($image);
    imagedestroy($watermark);
    ?>

    Decir que los ficheros .htaccess, watermark.php y watermark.png están colocados en el directorio raíz.

    Alguien se le ocurre algo de por qué no funciona?

    Gracias de antemano!

Viendo 2 respuestas - de la 1 a la 2 (de un total de 2)
  • Moderador erchache2000

    (@erchache2000)

    Yo mejor que realizar el marcado de las fotos en el server lo haría en local antes de subir las fotos.

    Aparte de disminuir las necesidades de ram y cpu en el hosting, no tendría nada en el server susceptible de que pudiese ser robado por algún scriptkiddie.

    Si tienes en el hosting las dos imagenes, la original y la marcada. Siempre pueden buscar la forma de robar la original…

    Iniciador del debate sguzgon

    (@sguzgon)

    La opción de realizarlo primero en local no es viable ya que no seré yo el que sube las imágenes. Por otra parte este método te obliga a tener montado en local el código para añadir la marca de agua en todos los PCs en los que vayas a subir imágenes.

    Me interesa la forma que propongo ya que no se hacen muchas peticiones al servidor, son unas imágenes en particular.

    Espero me puedan ayudar.

    Saludos.

Viendo 2 respuestas - de la 1 a la 2 (de un total de 2)
  • El debate ‘Watermark, php y .htaccess’ está cerrado a nuevas respuestas.