]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
moving around the watermarking code for supporting other image libs
authorCash Costello <cash.costello@gmail.com>
Sun, 12 Jul 2009 00:57:56 +0000 (00:57 +0000)
committerCash Costello <cash.costello@gmail.com>
Sun, 12 Jul 2009 00:57:56 +0000 (00:57 +0000)
actions/upload.php
lib/resize.php

index f062edc8017c609f3f801482ba613a5d274c354e..b74f72c7b2eae6fc5d02586d796266b5b4086c0d 100644 (file)
@@ -7,7 +7,6 @@
 \r
        global $CONFIG;\r
        include dirname(dirname(__FILE__)) . "/lib/resize.php";\r
-       include dirname(dirname(__FILE__)) . "/lib/watermark.php";\r
        include dirname(dirname(__FILE__)) . "/lib/exif.php";\r
 \r
        // Get common variables\r
 \r
                if ($image_lib == 'ImageMagick') { // ImageMagick command line\r
                        \r
-                       $thumbs = tp_create_imagick_cmdline_thumbnails($file, $prefix, $filestorename);\r
-                       if(!count($thumbs)) {\r
+                       if (tp_create_imagick_cmdline_thumbnails($file, $prefix, $filestorename) != true) {\r
                                trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick command line', E_USER_WARNING);\r
                        }\r
                        \r
-                       $album = get_entity($container_guid);\r
-                       \r
-                       tp_watermark($thumbs);\r
-                       \r
-                       \r
                } else if ($image_lib == 'ImageMagickPHP') {  // ImageMagick PHP \r
                        \r
                        if (tp_create_imagick_thumbnails($file, $prefix, $filestorename) != true) {\r
index a346fc272d69a4282db9f6a2c3eac35c3e43296d..a379d8c9384289113d21f9e8601f1c677b3a847b 100644 (file)
@@ -3,6 +3,8 @@
         * Elgg tidypics library of resizing functions\r
         * \r
         */\r
+        \r
+       include dirname(__FILE__) . "/watermark.php";\r
 \r
         \r
        /**\r
         */\r
        function tp_create_imagick_cmdline_thumbnails($file, $prefix, $filestorename)\r
        {\r
-               global $CONFIG;\r
-               \r
-               $mime = $file->getMimeType();\r
-               \r
                $image_sizes = get_plugin_setting('image_sizes', 'tidypics');\r
                if (!$image_sizes) {\r
                        register_error(elgg_echo('tidypics:nosettings'));\r
-                       return array();\r
+                       return false;\r
                }\r
                $image_sizes = unserialize($image_sizes);\r
+\r
+               $thumb = new ElggFile();\r
+\r
+\r
+               // tiny thumbnail\r
+               $thumb->setFilename($prefix."thumb".$filestorename);\r
+               $thumbname = $thumb->getFilenameOnFilestore();\r
+               $rtn_code = tp_imagick_cmdline_resize(  $file->getFilenameOnFilestore(),\r
+                                                                               $thumbname,\r
+                                                                               $image_sizes['thumb_image_width'],\r
+                                                                               $image_sizes['thumb_image_height'], \r
+                                                                               true);\r
+               if (!$rtn_code)\r
+                       return false;\r
+               $file->thumbnail = $prefix."thumb".$filestorename;\r
+\r
+\r
+               // album thumbnail\r
+               $thumb->setFilename($prefix."smallthumb".$filestorename);\r
+               $thumbname = $thumb->getFilenameOnFilestore();\r
+               $rtn_code = tp_imagick_cmdline_resize(  $file->getFilenameOnFilestore(),\r
+                                                                               $thumbname,\r
+                                                                               $image_sizes['small_image_width'],\r
+                                                                               $image_sizes['small_image_height'], \r
+                                                                               true); \r
+               if (!$rtn_code)\r
+                       return false;\r
+               $file->smallthumb = $prefix."smallthumb".$filestorename;\r
+\r
+\r
+               // main image\r
+               $thumb->setFilename($prefix."largethumb".$filestorename);\r
+               $thumbname = $thumb->getFilenameOnFilestore();\r
+               $rtn_code = tp_imagick_cmdline_resize(  $file->getFilenameOnFilestore(),\r
+                                                                               $thumbname,\r
+                                                                               $image_sizes['large_image_width'],\r
+                                                                               $image_sizes['large_image_height'], \r
+                                                                               false); \r
+               if (!$rtn_code)\r
+                       return false;\r
+               $file->largethumb = $prefix."largethumb".$filestorename;\r
                \r
-               $thumblarge = tp_imagick_cmdline_resize($file->getFilenameOnFilestore(), \r
-                                                               "largethumb", \r
-                                                               $image_sizes['large_image_width'], \r
-                                                               $image_sizes['large_image_height'], \r
-                                                               false); \r
-                                                                       \r
-               $thumbsmall = tp_imagick_cmdline_resize($file->getFilenameOnFilestore(), \r
-                                                               "smallthumb", \r
-                                                               $image_sizes['small_image_width'], \r
-                                                               $image_sizes['small_image_height'], \r
-                                                               true); \r
-\r
-               $thumbnail = tp_imagick_cmdline_resize($file->getFilenameOnFilestore(), \r
-                                                               "thumb", \r
-                                                               $image_sizes['thumb_image_width'], \r
-                                                               $image_sizes['thumb_image_height'], \r
-                                                               true);\r
-               \r
-               if ($thumbnail) {\r
-                       $thumb = new ElggFile();\r
-                       $thumb->setMimeType($mime);\r
-                       $thumb->setFilename($prefix."thumb".$filestorename);\r
-                       $file->thumbnail = $prefix."thumb".$filestorename;\r
-               }\r
-               \r
-               if ($thumbsmall) {\r
-                       $thumb = new ElggFile();\r
-                       $thumb->setMimeType($mime);\r
-                       $thumb->setFilename($prefix."smallthumb".$filestorename);\r
-                       $file->smallthumb = $prefix."smallthumb".$filestorename;\r
-               }\r
-               \r
-               if ($thumblarge) {\r
-                       $thumb = new ElggFile();\r
-                       $thumb->setMimeType($mime);\r
-                       $thumb->setFilename($prefix."largethumb".$filestorename);\r
-                       $file->largethumb = $prefix."largethumb".$filestorename;\r
-               }\r
+                                       \r
+                       //tp_watermark($thumbs);\r
+                       \r
+\r
 \r
-               return array(   "thumbnail" => $thumbnail,\r
-                                               "thumbsmall" => $thumbsmall,\r
-                                               "thumblarge" => $thumblarge);\r
+               unset($thumb);\r
+\r
+               return true;\r
        }\r
 \r
        /*\r
         * (Returns false if the uploaded file was not an image)\r
         *\r
         * @param string $input_name The name of the file input field on the submission form\r
-        * @param string $prefix The text to prefix to the existing filename\r
+        * @param string $output_name The name of the file to be written\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 false|mixed The contents of the resized image, or false on failure\r
+        * @return bool\r
         */\r
-       function tp_imagick_cmdline_resize($input_name, $prefix, $maxwidth, $maxheight, $square = false, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0) {\r
-\r
-               $params = array(\r
-                       "input_name"=>$input_name,\r
-                       "output_name"=>$output_name,\r
-                       "maxwidth"=>$maxwidth,\r
-                       "maxheight"=>$maxheight,\r
-                       "square"=>$square,\r
-                       "x1"=>$x1,\r
-                       "y1"=>$y1,\r
-                       "x2"=>$x2,\r
-                       "y2"=>$y2);\r
+       function tp_imagick_cmdline_resize($input_name, $output_name, $maxwidth, $maxheight, $square = false, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0) {\r
                \r
-               $path = pathinfo($input_name);\r
-               $output_name = $path["dirname"] . "/$prefix" . $path["filename"] . "." . $path["extension"];\r
                \r
                // Get the size information from the image\r
                if ($imgsizearray = getimagesize($input_name)) {\r
 \r
                        $accepted_formats = array(\r
                                                                                'image/jpeg' => 'jpeg',\r
+                                                                               'image/pjpeg' => 'jpeg',\r
                                                                                'image/png' => 'png',\r
+                                                                               'image/x-png' => 'png',\r
                                                                                'image/gif' => 'gif'\r
-                                                                               );\r
+                                                               );\r
                        // If it's a file we can manipulate ...\r
                        if (array_key_exists($imgsizearray['mime'],$accepted_formats)) {\r
 \r
                                if(substr($im_path, strlen($im_path)-1, 1) != "/") $im_path .= "/";\r
                                $command = $im_path . "convert \"$input_name\" -resize ".$newwidth."x".$newheight."^ -gravity center -extent ".$newwidth."x".$newheight." \"$output_name\"";\r
                                exec($command);\r
-                               return $output_name;\r
+                               return true;\r
 \r
                        }\r
                }\r