Version Description
- Fix: Error during upload of file types other than images (png, jpg)
- Fix: Limit watermark file types to png, gif, jpg
- Tweak: Validation for watermark size and transparency values
- Tweak: Remove unnecessary functions
- Tweak: Code cleanup
- Tweak: Added more code comments
- Tweak: Small css changes
Download this release
Release Info
Developer | dfactory |
Plugin | Image Watermark |
Version | 1.0.3 |
Comparing to | |
See all releases |
Code changes from version 1.0.2 to 1.0.3
- css/style.css +2 -1
- image-watermark.php +79 -117
- js/upload-manager.js +2 -2
- readme.txt +11 -2
css/style.css
CHANGED
@@ -31,4 +31,5 @@
|
|
31 |
}
|
32 |
#df-credits .inner { padding:15px 10px; }
|
33 |
#df-credits .df-link { font-family: Georgia,"Times New Roman","Bitstream Charter",Times,serif; font-style:italic; margin:0; }
|
34 |
-
#df-credits .df-link a { vertical-align: middle; padding: 5px 0 0 7px; }
|
|
31 |
}
|
32 |
#df-credits .inner { padding:15px 10px; }
|
33 |
#df-credits .df-link { font-family: Georgia,"Times New Roman","Bitstream Charter",Times,serif; font-style:italic; margin:0; }
|
34 |
+
#df-credits .df-link a { vertical-align: middle; padding: 5px 0 0 7px; }
|
35 |
+
#cpt-select { margin-top: 5px; }
|
image-watermark.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/*
|
3 |
Plugin Name: Image Watermark
|
4 |
Description: Image Watermark allows you to automatically watermark images uploaded to the WordPress Media Library.
|
5 |
-
Version: 1.0.
|
6 |
Author: dFactory
|
7 |
Author URI: http://www.dfactory.eu/
|
8 |
Plugin URI: http://www.dfactory.eu/plugins/image-watermark/
|
@@ -35,10 +35,14 @@ class ImageWatermark
|
|
35 |
'x' => array('left', 'center', 'right'),
|
36 |
'y' => array('top', 'middle', 'bottom'),
|
37 |
);
|
|
|
|
|
|
|
|
|
|
|
38 |
protected $_options = array(
|
39 |
'df_watermark_on' => array(),
|
40 |
-
'df_watermark_cpt_on' => array(),
|
41 |
-
'df_watermark_type' => 'image',
|
42 |
'df_watermark_image' => array(
|
43 |
'url' => 0,
|
44 |
'width' => 80,
|
@@ -70,21 +74,11 @@ class ImageWatermark
|
|
70 |
add_action('admin_enqueue_scripts', array(&$this, 'admin_watermark_scripts_styles'));
|
71 |
add_action('wp_enqueue_scripts', array(&$this, 'front_watermark_scripts_styles'));
|
72 |
add_action('admin_menu', array(&$this, 'watermark_admin_menu'));
|
73 |
-
|
74 |
//filters
|
75 |
add_filter('plugin_row_meta', array(&$this, 'plugin_extend_links'), 10, 2);
|
76 |
add_filter('plugin_action_links', array(&$this, 'plugin_settings_link'), 10, 2);
|
77 |
-
|
78 |
-
//check if post_id is "-1", meaning we're uploading watermark image
|
79 |
-
if(!(array_key_exists('post_id', $_REQUEST) && $_REQUEST['post_id'] == -1))
|
80 |
-
{
|
81 |
-
$watermark_image = $this->get_option('df_watermark_image');
|
82 |
-
|
83 |
-
if(!($watermark_image['plugin_off'] === 0 && $watermark_image['url'] === 0))
|
84 |
-
{
|
85 |
-
add_filter('wp_handle_upload_prefilter', array(&$this, 'delay_upload_filter'), 10, 1);
|
86 |
-
}
|
87 |
-
}
|
88 |
}
|
89 |
|
90 |
|
@@ -101,21 +95,25 @@ class ImageWatermark
|
|
101 |
|
102 |
|
103 |
/**
|
104 |
-
* Applies watermark everywhere or for specific post
|
105 |
*/
|
106 |
-
public function delay_upload_filter($
|
107 |
{
|
108 |
-
|
|
|
|
|
|
|
109 |
{
|
110 |
$option = get_option('df_watermark_cpt_on');
|
111 |
|
112 |
-
|
|
|
113 |
{
|
114 |
add_filter('wp_generate_attachment_metadata', array(&$this, 'apply_watermark'));
|
115 |
}
|
116 |
}
|
117 |
|
118 |
-
return $
|
119 |
}
|
120 |
|
121 |
|
@@ -223,7 +221,7 @@ class ImageWatermark
|
|
223 |
*/
|
224 |
public function front_watermark_scripts_styles()
|
225 |
{
|
226 |
-
$options =
|
227 |
|
228 |
if(($options['forlogged'] == 0 && is_user_logged_in()) || ($options['draganddrop'] == 0 && $options['rightclick'] == 0))
|
229 |
{
|
@@ -341,14 +339,20 @@ class ImageWatermark
|
|
341 |
{
|
342 |
switch($image_option)
|
343 |
{
|
|
|
|
|
|
|
|
|
|
|
344 |
case 'width':
|
|
|
|
|
|
|
345 |
case 'plugin_off':
|
346 |
-
case 'watermark_size_type':
|
347 |
case 'offset_width':
|
348 |
case 'offset_height':
|
349 |
case 'absolute_width':
|
350 |
case 'absolute_height':
|
351 |
-
case 'transparent':
|
352 |
$tmp[$image_option] = (int)(isset($_POST[$option][$image_option]) ? $_POST[$option][$image_option] : $this->_options[$option][$image_option]);
|
353 |
break;
|
354 |
|
@@ -397,10 +401,15 @@ class ImageWatermark
|
|
397 |
update_option($option, $value);
|
398 |
}
|
399 |
}
|
|
|
|
|
|
|
|
|
|
|
400 |
}
|
401 |
|
402 |
-
$watermark_image =
|
403 |
-
$image_protection =
|
404 |
|
405 |
if($watermark_image['plugin_off'] === 0 && $watermark_image['url'] === 0)
|
406 |
{
|
@@ -440,7 +449,7 @@ class ImageWatermark
|
|
440 |
<td class="wr_width">
|
441 |
<fieldset class="wr_width">
|
442 |
<legend class="screen-reader-text"><span><?php echo __('Enable watermark for', 'image-watermark'); ?></span></legend>
|
443 |
-
<?php $watermark_on = array_keys(
|
444 |
<div id="thumbnail-select">
|
445 |
<?php foreach($this->_image_sizes as $image_size) : ?>
|
446 |
<input name="df_watermark_on[<?php echo $image_size; ?>]" type="checkbox" id="<?php echo $image_size; ?>" value="1" <?php echo (in_array($image_size, $watermark_on) ? ' checked="checked"' : ''); ?> />
|
@@ -449,7 +458,7 @@ class ImageWatermark
|
|
449 |
</div>
|
450 |
<p class="howto"><?php echo __('Check image sizes on which watermark should appear.', 'image-watermark'); ?></p>
|
451 |
<legend class="screen-reader-text"><span><?php echo __('Enable watermark for', 'image-watermark'); ?></span></legend>
|
452 |
-
<?php $watermark_cpt_on = array_keys(
|
453 |
if(in_array('everywhere', $watermark_cpt_on) && count($watermark_cpt_on) === 1)
|
454 |
{ $first_checked = TRUE; $second_checked = FALSE; $watermark_cpt_on = array(); }
|
455 |
else { $first_checked = FALSE; $second_checked = TRUE; } ?>
|
@@ -516,7 +525,7 @@ class ImageWatermark
|
|
516 |
?>
|
517 |
|
518 |
<h3><?php echo __('Watermark image','image-watermark'); ?></h3>
|
519 |
-
<p class="howto"><?php echo __('Configure your watermark image. Allowed file formats are:
|
520 |
<table id="watermark-image-table" class="form-table">
|
521 |
<tr valign="top">
|
522 |
<th scope="row"><?php echo __('Watermark image','image-watermark'); ?></th>
|
@@ -653,46 +662,6 @@ class ImageWatermark
|
|
653 |
}
|
654 |
|
655 |
|
656 |
-
/**
|
657 |
-
* Get option by setting name with default value if option is unexistent
|
658 |
-
*
|
659 |
-
* @param string $setting
|
660 |
-
* @return mixed
|
661 |
-
*/
|
662 |
-
protected function get_option($setting)
|
663 |
-
{
|
664 |
-
if(is_array($this->_options[$setting]))
|
665 |
-
{
|
666 |
-
$options = array_merge($this->_options[$setting], get_option($setting));
|
667 |
-
}
|
668 |
-
else
|
669 |
-
{
|
670 |
-
$options = get_option($setting, $this->_options[$setting]);
|
671 |
-
}
|
672 |
-
|
673 |
-
return $options;
|
674 |
-
}
|
675 |
-
|
676 |
-
|
677 |
-
/**
|
678 |
-
* Get array with options
|
679 |
-
*
|
680 |
-
* @return array
|
681 |
-
*/
|
682 |
-
private function get_options()
|
683 |
-
{
|
684 |
-
$options = array();
|
685 |
-
|
686 |
-
//loop through default options and get user defined options
|
687 |
-
foreach($this->_options as $option => $value)
|
688 |
-
{
|
689 |
-
$options[$option] = $this->get_option($option);
|
690 |
-
}
|
691 |
-
|
692 |
-
return $options;
|
693 |
-
}
|
694 |
-
|
695 |
-
|
696 |
/**
|
697 |
* Plugin installation method
|
698 |
*/
|
@@ -700,7 +669,6 @@ class ImageWatermark
|
|
700 |
{
|
701 |
//record install time
|
702 |
add_option('df_watermark_installed', time(), NULL, 'no');
|
703 |
-
add_option('df_watermark_cpt_on', array('everywhere'), NULL, 'no');
|
704 |
|
705 |
//loop through default options and add them into DB
|
706 |
foreach($this->_options as $option => $value)
|
@@ -720,12 +688,12 @@ class ImageWatermark
|
|
720 |
{
|
721 |
//get settings for watermarking
|
722 |
$upload_dir = wp_upload_dir();
|
723 |
-
$watermark_on =
|
724 |
|
725 |
-
//loop through image sizes
|
726 |
-
foreach($watermark_on as $image_size => $
|
727 |
{
|
728 |
-
if($
|
729 |
{
|
730 |
switch($image_size)
|
731 |
{
|
@@ -759,32 +727,31 @@ class ImageWatermark
|
|
759 |
* Apply watermark to certain image
|
760 |
*
|
761 |
* @param string $filepath
|
762 |
-
* @return boolean
|
763 |
*/
|
764 |
public function do_watermark($filepath)
|
765 |
{
|
766 |
-
|
767 |
-
$mime_type = wp_check_filetype($filepath);
|
768 |
-
$mime_type = $mime_type['type'];
|
769 |
-
//get watermark settings
|
770 |
-
$options = $this->get_options();
|
771 |
|
772 |
-
|
|
|
773 |
{
|
774 |
-
|
775 |
}
|
776 |
|
777 |
-
//get image
|
778 |
-
$
|
|
|
779 |
|
780 |
-
|
|
|
781 |
{
|
782 |
//add watermark image to image
|
783 |
-
$this->add_watermark_image($image, $options)
|
|
|
|
|
|
|
|
|
784 |
}
|
785 |
-
|
786 |
-
//save watermarked image
|
787 |
-
return $this->save_image_file($image, $mime_type, $filepath);
|
788 |
}
|
789 |
|
790 |
|
@@ -800,22 +767,25 @@ class ImageWatermark
|
|
800 |
//get size and url of watermark
|
801 |
$size_type = $opt['df_watermark_image']['watermark_size_type'];
|
802 |
$url = wp_get_attachment_url($opt['df_watermark_image']['url']);
|
803 |
-
$
|
804 |
-
$ext = $file['extension'];
|
805 |
|
806 |
-
switch($
|
807 |
{
|
808 |
-
case '
|
809 |
-
case '
|
810 |
-
$watermark = imagecreatefromjpeg(
|
|
|
|
|
|
|
|
|
811 |
break;
|
812 |
|
813 |
-
case '
|
814 |
-
$watermark =
|
815 |
break;
|
816 |
|
817 |
default:
|
818 |
-
|
819 |
}
|
820 |
|
821 |
$watermark_width = imagesx($watermark);
|
@@ -823,19 +793,19 @@ class ImageWatermark
|
|
823 |
$img_width = imagesx($image);
|
824 |
$img_height = imagesy($image);
|
825 |
|
826 |
-
if($size_type
|
827 |
{
|
828 |
$w = $opt['df_watermark_image']['absolute_width'];
|
829 |
$h = $opt['df_watermark_image']['absolute_height'];
|
830 |
}
|
831 |
-
elseif($size_type
|
832 |
{
|
833 |
$size = $opt['df_watermark_image']['width'] / 100;
|
834 |
$ratio = (($img_width * $size) / $watermark_width);
|
835 |
$w = ($watermark_width * $ratio);
|
836 |
$h = ($watermark_height * $ratio);
|
837 |
}
|
838 |
-
else
|
839 |
{
|
840 |
$size = 1;
|
841 |
$w = ($watermark_width * $size);
|
@@ -901,7 +871,7 @@ class ImageWatermark
|
|
901 |
|
902 |
|
903 |
/**
|
904 |
-
*
|
905 |
*/
|
906 |
private function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct)
|
907 |
{
|
@@ -924,8 +894,8 @@ class ImageWatermark
|
|
924 |
$imgInfo = getimagesize($path);
|
925 |
$newImg = imagecreateTRUEcolor($nWidth, $nHeight);
|
926 |
|
927 |
-
//check if this image is PNG
|
928 |
-
if($imgInfo[2]
|
929 |
{
|
930 |
imagealphablending($newImg, FALSE);
|
931 |
imagesavealpha($newImg, TRUE);
|
@@ -950,6 +920,7 @@ class ImageWatermark
|
|
950 |
switch($mime_type)
|
951 |
{
|
952 |
case 'image/jpeg':
|
|
|
953 |
return imagecreatefromjpeg($filepath);
|
954 |
|
955 |
case 'image/png':
|
@@ -958,12 +929,6 @@ class ImageWatermark
|
|
958 |
imagefilledrectangle($res, 0, 0, imagesx($res), imagesy($res), $transparent);
|
959 |
return $res;
|
960 |
|
961 |
-
case 'image/gif':
|
962 |
-
$res = imagecreatefromgif($filepath);
|
963 |
-
$transparent = imagecolorallocatealpha($res, 255, 255, 254, 127);
|
964 |
-
imagefilledrectangle($res, 0, 0, imagesx($res), imagesy($res), $transparent);
|
965 |
-
return $res;
|
966 |
-
|
967 |
default:
|
968 |
return FALSE;
|
969 |
}
|
@@ -983,16 +948,13 @@ class ImageWatermark
|
|
983 |
switch($mime_type)
|
984 |
{
|
985 |
case 'image/jpeg':
|
986 |
-
|
|
|
|
|
987 |
|
988 |
case 'image/png':
|
989 |
-
|
990 |
-
|
991 |
-
case 'image/gif':
|
992 |
-
return imagegif($image, $filepath);
|
993 |
-
|
994 |
-
default:
|
995 |
-
return FALSE;
|
996 |
}
|
997 |
}
|
998 |
}
|
2 |
/*
|
3 |
Plugin Name: Image Watermark
|
4 |
Description: Image Watermark allows you to automatically watermark images uploaded to the WordPress Media Library.
|
5 |
+
Version: 1.0.3
|
6 |
Author: dFactory
|
7 |
Author URI: http://www.dfactory.eu/
|
8 |
Plugin URI: http://www.dfactory.eu/plugins/image-watermark/
|
35 |
'x' => array('left', 'center', 'right'),
|
36 |
'y' => array('top', 'middle', 'bottom'),
|
37 |
);
|
38 |
+
private $_allowed_mime_types = array(
|
39 |
+
'image/jpeg',
|
40 |
+
'image/pjpeg',
|
41 |
+
'image/png'
|
42 |
+
);
|
43 |
protected $_options = array(
|
44 |
'df_watermark_on' => array(),
|
45 |
+
'df_watermark_cpt_on' => array('everywhere'),
|
|
|
46 |
'df_watermark_image' => array(
|
47 |
'url' => 0,
|
48 |
'width' => 80,
|
74 |
add_action('admin_enqueue_scripts', array(&$this, 'admin_watermark_scripts_styles'));
|
75 |
add_action('wp_enqueue_scripts', array(&$this, 'front_watermark_scripts_styles'));
|
76 |
add_action('admin_menu', array(&$this, 'watermark_admin_menu'));
|
77 |
+
|
78 |
//filters
|
79 |
add_filter('plugin_row_meta', array(&$this, 'plugin_extend_links'), 10, 2);
|
80 |
add_filter('plugin_action_links', array(&$this, 'plugin_settings_link'), 10, 2);
|
81 |
+
add_filter('wp_handle_upload_prefilter', array(&$this, 'delay_upload_filter'), 10, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
}
|
83 |
|
84 |
|
95 |
|
96 |
|
97 |
/**
|
98 |
+
* Applies watermark everywhere or for specific post types
|
99 |
*/
|
100 |
+
public function delay_upload_filter($file)
|
101 |
{
|
102 |
+
$option_wi = get_option('df_watermark_image');
|
103 |
+
|
104 |
+
//if plugin is activated and turned on and watermark image is set and uploaded file is an image
|
105 |
+
if($option_wi['plugin_off'] === 0 && $option_wi['url'] !== 0 && isset($_REQUEST['post_id']) && in_array($file['type'], $this->_allowed_mime_types))
|
106 |
{
|
107 |
$option = get_option('df_watermark_cpt_on');
|
108 |
|
109 |
+
//when apply watermark? everywhere or specific custom post types
|
110 |
+
if((isset($option[0]) && $option[0] === 'everywhere') || in_array(get_post_type($_REQUEST['post_id']), array_keys($option)) === TRUE)
|
111 |
{
|
112 |
add_filter('wp_generate_attachment_metadata', array(&$this, 'apply_watermark'));
|
113 |
}
|
114 |
}
|
115 |
|
116 |
+
return $file;
|
117 |
}
|
118 |
|
119 |
|
221 |
*/
|
222 |
public function front_watermark_scripts_styles()
|
223 |
{
|
224 |
+
$options = get_option('df_image_protection');
|
225 |
|
226 |
if(($options['forlogged'] == 0 && is_user_logged_in()) || ($options['draganddrop'] == 0 && $options['rightclick'] == 0))
|
227 |
{
|
339 |
{
|
340 |
switch($image_option)
|
341 |
{
|
342 |
+
case 'watermark_size_type':
|
343 |
+
$tmp[$image_option] = (int)(isset($_POST[$option][$image_option]) && in_array($_POST[$option][$image_option], array(0, 1, 2)) ? $_POST[$option][$image_option] : $this->_options[$option][$image_option]);
|
344 |
+
break;
|
345 |
+
|
346 |
+
case 'transparent':
|
347 |
case 'width':
|
348 |
+
$tmp[$image_option] = (isset($_POST[$option][$image_option]) ? ($_POST[$option][$image_option] <= 0 ? 0 : ($_POST[$option][$image_option] >= 100 ? 100 : (int)$_POST[$option][$image_option])) : $this->_options[$option][$image_option]);
|
349 |
+
break;
|
350 |
+
|
351 |
case 'plugin_off':
|
|
|
352 |
case 'offset_width':
|
353 |
case 'offset_height':
|
354 |
case 'absolute_width':
|
355 |
case 'absolute_height':
|
|
|
356 |
$tmp[$image_option] = (int)(isset($_POST[$option][$image_option]) ? $_POST[$option][$image_option] : $this->_options[$option][$image_option]);
|
357 |
break;
|
358 |
|
401 |
update_option($option, $value);
|
402 |
}
|
403 |
}
|
404 |
+
|
405 |
+
echo '
|
406 |
+
<div class="updated">
|
407 |
+
<p>'.__('Settings saved.').'</p>
|
408 |
+
</div>';
|
409 |
}
|
410 |
|
411 |
+
$watermark_image = get_option('df_watermark_image');
|
412 |
+
$image_protection = get_option('df_image_protection');
|
413 |
|
414 |
if($watermark_image['plugin_off'] === 0 && $watermark_image['url'] === 0)
|
415 |
{
|
449 |
<td class="wr_width">
|
450 |
<fieldset class="wr_width">
|
451 |
<legend class="screen-reader-text"><span><?php echo __('Enable watermark for', 'image-watermark'); ?></span></legend>
|
452 |
+
<?php $watermark_on = array_keys(get_option('df_watermark_on')); ?>
|
453 |
<div id="thumbnail-select">
|
454 |
<?php foreach($this->_image_sizes as $image_size) : ?>
|
455 |
<input name="df_watermark_on[<?php echo $image_size; ?>]" type="checkbox" id="<?php echo $image_size; ?>" value="1" <?php echo (in_array($image_size, $watermark_on) ? ' checked="checked"' : ''); ?> />
|
458 |
</div>
|
459 |
<p class="howto"><?php echo __('Check image sizes on which watermark should appear.', 'image-watermark'); ?></p>
|
460 |
<legend class="screen-reader-text"><span><?php echo __('Enable watermark for', 'image-watermark'); ?></span></legend>
|
461 |
+
<?php $watermark_cpt_on = array_keys(get_option('df_watermark_cpt_on'));
|
462 |
if(in_array('everywhere', $watermark_cpt_on) && count($watermark_cpt_on) === 1)
|
463 |
{ $first_checked = TRUE; $second_checked = FALSE; $watermark_cpt_on = array(); }
|
464 |
else { $first_checked = FALSE; $second_checked = TRUE; } ?>
|
525 |
?>
|
526 |
|
527 |
<h3><?php echo __('Watermark image','image-watermark'); ?></h3>
|
528 |
+
<p class="howto"><?php echo __('Configure your watermark image. Allowed file formats are: JPEG, PNG, GIF.','image-watermark'); ?></p>
|
529 |
<table id="watermark-image-table" class="form-table">
|
530 |
<tr valign="top">
|
531 |
<th scope="row"><?php echo __('Watermark image','image-watermark'); ?></th>
|
662 |
}
|
663 |
|
664 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
665 |
/**
|
666 |
* Plugin installation method
|
667 |
*/
|
669 |
{
|
670 |
//record install time
|
671 |
add_option('df_watermark_installed', time(), NULL, 'no');
|
|
|
672 |
|
673 |
//loop through default options and add them into DB
|
674 |
foreach($this->_options as $option => $value)
|
688 |
{
|
689 |
//get settings for watermarking
|
690 |
$upload_dir = wp_upload_dir();
|
691 |
+
$watermark_on = get_option('df_watermark_on');
|
692 |
|
693 |
+
//loop through active image sizes
|
694 |
+
foreach($watermark_on as $image_size => $active_size)
|
695 |
{
|
696 |
+
if($active_size === 1)
|
697 |
{
|
698 |
switch($image_size)
|
699 |
{
|
727 |
* Apply watermark to certain image
|
728 |
*
|
729 |
* @param string $filepath
|
|
|
730 |
*/
|
731 |
public function do_watermark($filepath)
|
732 |
{
|
733 |
+
$options = array();
|
|
|
|
|
|
|
|
|
734 |
|
735 |
+
//get watermark settings
|
736 |
+
foreach($this->_options as $option => $value)
|
737 |
{
|
738 |
+
$options[$option] = get_option($option);
|
739 |
}
|
740 |
|
741 |
+
//get image mime type
|
742 |
+
$mime_type = wp_check_filetype($filepath);
|
743 |
+
$mime_type = $mime_type['type'];
|
744 |
|
745 |
+
//get image resource
|
746 |
+
if(($image = $this->get_image_resource($filepath, $mime_type)) !== FALSE)
|
747 |
{
|
748 |
//add watermark image to image
|
749 |
+
if($this->add_watermark_image($image, $options) !== FALSE)
|
750 |
+
{
|
751 |
+
//save watermarked image
|
752 |
+
$this->save_image_file($image, $mime_type, $filepath);
|
753 |
+
}
|
754 |
}
|
|
|
|
|
|
|
755 |
}
|
756 |
|
757 |
|
767 |
//get size and url of watermark
|
768 |
$size_type = $opt['df_watermark_image']['watermark_size_type'];
|
769 |
$url = wp_get_attachment_url($opt['df_watermark_image']['url']);
|
770 |
+
$watermark_file = getimagesize($url);
|
|
|
771 |
|
772 |
+
switch($watermark_file['mime'])
|
773 |
{
|
774 |
+
case 'image/jpeg':
|
775 |
+
case 'image/pjpeg':
|
776 |
+
$watermark = imagecreatefromjpeg($url);
|
777 |
+
break;
|
778 |
+
|
779 |
+
case 'image/gif':
|
780 |
+
$watermark = imagecreatefromgif($url);
|
781 |
break;
|
782 |
|
783 |
+
case 'image/png':
|
784 |
+
$watermark = imagecreatefrompng($url);
|
785 |
break;
|
786 |
|
787 |
default:
|
788 |
+
return FALSE;
|
789 |
}
|
790 |
|
791 |
$watermark_width = imagesx($watermark);
|
793 |
$img_width = imagesx($image);
|
794 |
$img_height = imagesy($image);
|
795 |
|
796 |
+
if($size_type === 1) //custom
|
797 |
{
|
798 |
$w = $opt['df_watermark_image']['absolute_width'];
|
799 |
$h = $opt['df_watermark_image']['absolute_height'];
|
800 |
}
|
801 |
+
elseif($size_type === 2) //scale
|
802 |
{
|
803 |
$size = $opt['df_watermark_image']['width'] / 100;
|
804 |
$ratio = (($img_width * $size) / $watermark_width);
|
805 |
$w = ($watermark_width * $ratio);
|
806 |
$h = ($watermark_height * $ratio);
|
807 |
}
|
808 |
+
else //original
|
809 |
{
|
810 |
$size = 1;
|
811 |
$w = ($watermark_width * $size);
|
871 |
|
872 |
|
873 |
/**
|
874 |
+
* Creates new image
|
875 |
*/
|
876 |
private function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct)
|
877 |
{
|
894 |
$imgInfo = getimagesize($path);
|
895 |
$newImg = imagecreateTRUEcolor($nWidth, $nHeight);
|
896 |
|
897 |
+
//check if this image is PNG, then set if transparent
|
898 |
+
if($imgInfo[2] === 3)
|
899 |
{
|
900 |
imagealphablending($newImg, FALSE);
|
901 |
imagesavealpha($newImg, TRUE);
|
920 |
switch($mime_type)
|
921 |
{
|
922 |
case 'image/jpeg':
|
923 |
+
case 'image/pjpeg':
|
924 |
return imagecreatefromjpeg($filepath);
|
925 |
|
926 |
case 'image/png':
|
929 |
imagefilledrectangle($res, 0, 0, imagesx($res), imagesy($res), $transparent);
|
930 |
return $res;
|
931 |
|
|
|
|
|
|
|
|
|
|
|
|
|
932 |
default:
|
933 |
return FALSE;
|
934 |
}
|
948 |
switch($mime_type)
|
949 |
{
|
950 |
case 'image/jpeg':
|
951 |
+
case 'image/pjpeg':
|
952 |
+
imagejpeg($image, $filepath, apply_filters('jpeg_quality', 90));
|
953 |
+
break;
|
954 |
|
955 |
case 'image/png':
|
956 |
+
imagepng($image, $filepath);
|
957 |
+
break;
|
|
|
|
|
|
|
|
|
|
|
958 |
}
|
959 |
}
|
960 |
}
|
js/upload-manager.js
CHANGED
@@ -10,11 +10,11 @@ jQuery(document).ready(function($) {
|
|
10 |
button: upload_manager_args.button,
|
11 |
multiple: upload_manager_args.multiple,
|
12 |
library: {
|
13 |
-
type: 'image'
|
14 |
}
|
15 |
});
|
16 |
|
17 |
-
this._frameWatermark.on(
|
18 |
return this._frameWatermark;
|
19 |
},
|
20 |
select: function() {
|
10 |
button: upload_manager_args.button,
|
11 |
multiple: upload_manager_args.multiple,
|
12 |
library: {
|
13 |
+
type: ['image/gif', 'image/jpg', 'image/jpeg', 'image/png']
|
14 |
}
|
15 |
});
|
16 |
|
17 |
+
this._frameWatermark.on('open', this.updateFrame).state('library').on('select', this.select);
|
18 |
return this._frameWatermark;
|
19 |
},
|
20 |
select: function() {
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.dfactory.eu/
|
|
4 |
Tags: image, images, picture, watermark, watermarking, protection, image protection, image security
|
5 |
Requires at least: 3.5
|
6 |
Tested up to: 3.5.1
|
7 |
-
Stable tag: 1.0.
|
8 |
License: MIT License
|
9 |
License URI: http://opensource.org/licenses/MIT
|
10 |
|
@@ -48,6 +48,15 @@ No questions yet.
|
|
48 |
|
49 |
== Changelog ==
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
= 1.0.2 =
|
52 |
* New: Add watermark to custom images sizes registered in theme
|
53 |
* Tweak: Admin notices on settings page if no watermark image selected
|
@@ -63,4 +72,4 @@ Initial release
|
|
63 |
|
64 |
== Upgrade Notice ==
|
65 |
|
66 |
-
|
4 |
Tags: image, images, picture, watermark, watermarking, protection, image protection, image security
|
5 |
Requires at least: 3.5
|
6 |
Tested up to: 3.5.1
|
7 |
+
Stable tag: 1.0.3
|
8 |
License: MIT License
|
9 |
License URI: http://opensource.org/licenses/MIT
|
10 |
|
48 |
|
49 |
== Changelog ==
|
50 |
|
51 |
+
= 1.0.3 =
|
52 |
+
* Fix: Error during upload of file types other than images (png, jpg)
|
53 |
+
* Fix: Limit watermark file types to png, gif, jpg
|
54 |
+
* Tweak: Validation for watermark size and transparency values
|
55 |
+
* Tweak: Remove unnecessary functions
|
56 |
+
* Tweak: Code cleanup
|
57 |
+
* Tweak: Added more code comments
|
58 |
+
* Tweak: Small css changes
|
59 |
+
|
60 |
= 1.0.2 =
|
61 |
* New: Add watermark to custom images sizes registered in theme
|
62 |
* Tweak: Admin notices on settings page if no watermark image selected
|
72 |
|
73 |
== Upgrade Notice ==
|
74 |
|
75 |
+
Fix: Error during upload of file types other than images (png, jpg)
|