diff options
author | omar <omma2289@bitbucket.org> | 2015-01-31 19:57:07 +0100 |
---|---|---|
committer | omar <omma2289@bitbucket.org> | 2015-01-31 19:57:07 +0100 |
commit | 0779e99eeb12cb137eed77cf580add374afa71a5 (patch) | |
tree | 1ec7b4d4a3ccf9022ef177e90f84e50c264f2baf /system | |
parent | 7a5e3da936ffaab0ebd7d07dbf5e3737ff91c440 (diff) |
Fixed Watermark function to work without drop shadow
Diffstat (limited to 'system')
-rw-r--r-- | system/libraries/Image_lib.php | 76 |
1 files changed, 46 insertions, 30 deletions
diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 92e47507f..aae062e47 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1311,12 +1311,14 @@ class CI_Image_lib { $y_axis = $this->wm_vrt_offset + $this->wm_padding; if ($this->wm_use_drop_shadow === FALSE) + { $this->wm_shadow_distance = 0; + } $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]); $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]); - // Set verticle alignment + // Set vertical alignment if ($this->wm_vrt_alignment === 'M') { $y_axis += ($this->orig_height / 2) + ($fontheight / 2); @@ -1325,53 +1327,67 @@ class CI_Image_lib { { $y_axis += $this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight / 2); } - - $x_shad = $x_axis + $this->wm_shadow_distance; - $y_shad = $y_axis + $this->wm_shadow_distance; - + + // Set horizontal alignment + if ($this->wm_hor_alignment === 'R') + { + $x_axis += $this->orig_width - ($fontwidth * strlen($this->wm_text)); + } + elseif ($this->wm_hor_alignment === 'C') + { + $x_axis += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2); + } + if ($this->wm_use_drop_shadow) { - // Set horizontal alignment - if ($this->wm_hor_alignment === 'R') - { - $x_shad += $this->orig_width - ($fontwidth * strlen($this->wm_text)); - $x_axis += $this->orig_width - ($fontwidth * strlen($this->wm_text)); - } - elseif ($this->wm_hor_alignment === 'C') - { - $x_shad += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2); - $x_axis += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2); - } - - /* Set RGB values for text and shadow + // Offset from text + $x_shad = $x_axis + $this->wm_shadow_distance; + $y_shad = $y_axis + $this->wm_shadow_distance; + + /* Set RGB values for shadow * * First character is #, so we don't really need it. * Get the rest of the string and split it into 2-length * hex values: */ - $txt_color = str_split(substr($this->wm_font_color, 1, 6), 2); - $txt_color = imagecolorclosest($src_img, hexdec($txt_color[0]), hexdec($txt_color[1]), hexdec($txt_color[2])); $drp_color = str_split(substr($this->wm_shadow_color, 1, 6), 2); $drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[1]), hexdec($drp_color[2])); - - // Add the text to the source image + + // Add the shadow to the source image if ($this->wm_use_truetype) { imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); - imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); } else { imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); - imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); } + } + + /* Set RGB values for text + * + * First character is #, so we don't really need it. + * Get the rest of the string and split it into 2-length + * hex values: + */ + $txt_color = str_split(substr($this->wm_font_color, 1, 6), 2); + $txt_color = imagecolorclosest($src_img, hexdec($txt_color[0]), hexdec($txt_color[1]), hexdec($txt_color[2])); - // We can preserve transparency for PNG images - if ($this->image_type === 3) - { - imagealphablending($src_img, FALSE); - imagesavealpha($src_img, TRUE); - } + // Add the text to the source image + if ($this->wm_use_truetype) + { + imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); + } + else + { + imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); + } + + // We can preserve transparency for PNG images + if ($this->image_type === 3) + { + imagealphablending($src_img, FALSE); + imagesavealpha($src_img, TRUE); } // Output the final image |