]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
continue to build watermarking code
authorCash Costello <cash.costello@gmail.com>
Fri, 17 Jul 2009 00:37:28 +0000 (00:37 +0000)
committerCash Costello <cash.costello@gmail.com>
Fri, 17 Jul 2009 00:37:28 +0000 (00:37 +0000)
lib/resize.php
lib/watermark.php

index 894a68fff8eca96de05b2cea904f3324c7aeda7a..803cb8fa7601172ddc3a6e31f87cf659cb73ae21 100644 (file)
@@ -34,6 +34,7 @@
                $thumbname = $thumb->getFilenameOnFilestore();\r
                $rtn_code = tp_gd_resize(       $file->getFilenameOnFilestore(),\r
                                                                        $thumbname,\r
+                                                                       false,\r
                                                                        $image_sizes['thumb_image_width'],\r
                                                                        $image_sizes['thumb_image_height'], \r
                                                                        true);\r
@@ -47,6 +48,7 @@
                $thumbname = $thumb->getFilenameOnFilestore();\r
                $rtn_code = tp_gd_resize(       $file->getFilenameOnFilestore(),\r
                                                                        $thumbname,\r
+                                                                       false,\r
                                                                        $image_sizes['small_image_width'],\r
                                                                        $image_sizes['small_image_height'], \r
                                                                        true); \r
@@ -60,6 +62,7 @@
                $thumbname = $thumb->getFilenameOnFilestore();\r
                $rtn_code = tp_gd_resize(       $file->getFilenameOnFilestore(),\r
                                                                        $thumbname,\r
+                                                                       true,\r
                                                                        $image_sizes['large_image_width'],\r
                                                                        $image_sizes['large_image_height'], \r
                                                                        false); \r
@@ -67,7 +70,6 @@
                        return false;\r
                $file->largethumb = $prefix."largethumb".$filestorename;\r
                \r
-               tp_gd_watermark($thumbname);\r
 \r
                unset($thumb);\r
 \r
         *\r
         * @param string $input_name The name of the file on the disk\r
         * @param string $output_name The name of the file to be written\r
+        * @param bool - watermark this image? \r
         * @param int $maxwidth The maximum width of the resized image\r
         * @param int $maxheight The maximum height of the resized image\r
         * @param true|false $square If set to true, will take the smallest of maxwidth and maxheight and use it to set the dimensions on all size; the image will be cropped.\r
         * @return bool true on success or false on failure\r
         */\r
-       function tp_gd_resize($input_name, $output_name, $maxwidth, $maxheight, $square = false, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0) {\r
+       function tp_gd_resize($input_name, $output_name, $watermark, $maxwidth, $maxheight, $square = false, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0) {\r
                \r
                // Get the size information from the image\r
                $imgsizearray = getimagesize($input_name);\r
                if (!rtn_code)\r
                        return $rtn_code;\r
                \r
+               if ($watermark)\r
+                       tp_gd_watermark($newimage);\r
+               \r
                switch ($imgsizearray['mime']) {\r
                        case 'image/jpeg':\r
                        case 'image/pjpeg':\r
index b80e1b9e9149855ba6875fdcae116a0a763968e5..2263bdd8f3a3f6762346a10a5bd075a3a1115619 100644 (file)
@@ -22,7 +22,31 @@ function tp_get_watermark_filename($text, $owner) {
        return $filename;
 }
 
-function tp_gd_watermark($filename) {
+function tp_gd_watermark($image) {
+       $watermark_text = get_plugin_setting('watermark_text', 'tidypics');
+       if (!$watermark_text)
+               return;
+       
+       
+       $owner = get_loggedin_user();
+
+       $watermark_text = tp_process_watermark_text($watermark_text, $owner);
+       
+       
+       
+       $font = 5;
+       $line_width = strlen($watermark_text) * imagefontwidth($font);
+       $line_height = imagefontheight($font);
+       
+       $image_width = 600;
+       $image_height = 450;
+       
+       // matching -gravity south -geometry +0+10
+       $top = $image_height - $line_height - 10;
+       $left = round(($image_width - $line_width) / 2);
+       
+       $textcolor = imagecolorallocate($image, 0, 0, 255);
+       imagestring($image, $font, $left, $top, $watermark_text, $textcolor);
 }
 
 function tp_imagick_watermark($filename) {