Note that there are some explanatory texts on larger screens.

plurals
  1. PODifferent watermark image depending on size of original image
    primarykey
    data
    text
    <p>I have the following code, which I sourced at <a href="http://dolcepixel.com/how-to-watermark-all-your-uploaded-images/" rel="nofollow">http://dolcepixel.com/how-to-watermark-all-your-uploaded-images/</a></p> <p>I need to modify the code to use a different watermark image if the original image is below a certain size.</p> <p>I see there is a line of code regarding not applying the watermark if it is below 150x150 but how could this be modified to use a different watermark rather than no watermark?</p> <pre><code>&lt;?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 = 'c'; $q = $_GET['q']; if(!$q || $q&lt;0 || $q&gt;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("MTP-logo", $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 &lt; "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); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload