Easy Watermark - Version 0.2

Version Description

  • added text watermark handling
  • corrected issue with auto adding watermark on upload
Download this release

Release Info

Developer szaleq
Plugin Icon Easy Watermark
Version 0.2
Comparing to
See all releases

Code changes from version 0.1.1 to 0.2

Files changed (55) hide show
  1. EasyWatermark.php +341 -105
  2. EasyWatermarkPlugin.php +139 -66
  3. EasyWatermarkSettings.php +89 -32
  4. css/colorpicker.css +161 -0
  5. css/style.css +16 -0
  6. fonts/Arial.ttf +0 -0
  7. fonts/Arial_Black.ttf +0 -0
  8. fonts/Comic_Sans_MS.ttf +0 -0
  9. fonts/Courier_New.ttf +0 -0
  10. fonts/Georgia.ttf +0 -0
  11. fonts/Impact.ttf +0 -0
  12. fonts/Tahoma.ttf +0 -0
  13. fonts/Times_New_Roman.ttf +0 -0
  14. fonts/Trebuchet_MS.ttf +0 -0
  15. fonts/Verdana.ttf +0 -0
  16. images/Thumbs.db +0 -0
  17. images/blank.gif +0 -0
  18. images/colorpicker_background.png +0 -0
  19. images/colorpicker_hex.png +0 -0
  20. images/colorpicker_hsb_b.png +0 -0
  21. images/colorpicker_hsb_h.png +0 -0
  22. images/colorpicker_hsb_s.png +0 -0
  23. images/colorpicker_indic.gif +0 -0
  24. images/colorpicker_overlay.png +0 -0
  25. images/colorpicker_rgb_b.png +0 -0
  26. images/colorpicker_rgb_g.png +0 -0
  27. images/colorpicker_rgb_r.png +0 -0
  28. images/colorpicker_select.gif +0 -0
  29. images/colorpicker_submit.png +0 -0
  30. images/custom_background.png +0 -0
  31. images/custom_hex.png +0 -0
  32. images/custom_hsb_b.png +0 -0
  33. images/custom_hsb_h.png +0 -0
  34. images/custom_hsb_s.png +0 -0
  35. images/custom_indic.gif +0 -0
  36. images/custom_rgb_b.png +0 -0
  37. images/custom_rgb_g.png +0 -0
  38. images/custom_rgb_r.png +0 -0
  39. images/custom_submit.png +0 -0
  40. images/select.png +0 -0
  41. images/select2.png +0 -0
  42. images/slider.png +0 -0
  43. index.php +6 -3
  44. js/colorpicker.js +484 -0
  45. js/interface.js +10 -0
  46. languages/easy-watermark-pl_PL.mo +0 -0
  47. languages/easy-watermark-pl_PL.po +127 -67
  48. languages/easy-watermark.pot +128 -67
  49. plugin.php +139 -0
  50. readme.txt +17 -5
  51. screenshot-1.png +0 -0
  52. settings-form-general.php +23 -0
  53. settings-form-image.php +41 -0
  54. settings-form-text.php +46 -0
  55. settings-form.php +13 -57
EasyWatermark.php CHANGED
@@ -1,7 +1,7 @@
1
<?php
2
/**
3
* @package Easy Watermark
4
- * @version 1.0
5
* @license GPL
6
* @author Wojtek Szałkiewicz
7
* @author url http://szalkiewicz.pl
@@ -32,9 +32,10 @@
32
* You can also specify custom output format, and save it as file using saveOutput method.
33
* TODO:
34
* - watermark scaling
35
- * - adding text watermark
36
* Any other ideas, pleas contact me.
37
*/
38
39
class EasyWatermark
40
{
@@ -42,11 +43,25 @@ class EasyWatermark
42
* @var array default settings
43
*/
44
private $defaultSettings = array(
45
- 'position_x' => 2,
46
- 'position_y' => 2,
47
- 'offset_x' => 0,
48
- 'offset_y' => 0,
49
- 'opacity' => 100
50
);
51
52
/**
@@ -84,6 +99,11 @@ class EasyWatermark
84
*/
85
private $outputMime = '';
86
87
/**
88
* @var string error message
89
*/
@@ -94,12 +114,13 @@ class EasyWatermark
94
*
95
* @param array settings
96
*/
97
- public function __construct($settings = array()){
98
- $this->set($settings);
99
}
100
101
/**
102
- * Sets all needed parameters (settings and values of some private fields)
103
*
104
* @see $defaultSettings
105
* @chainable
@@ -107,11 +128,11 @@ class EasyWatermark
107
* @param string value
108
* @return object $this
109
*/
110
- public function set($key, $val = null){
111
if(is_array($key)){
112
// act recursive
113
foreach($key as $k => $v){
114
- $this->set($k, $v);
115
}
116
return $this;
117
}
@@ -136,13 +157,54 @@ class EasyWatermark
136
$this->setOutputMime($val);
137
break;
138
default:
139
- $this->settings[$key] = $val;
140
break;
141
}
142
143
return $this;
144
}
145
146
/**
147
* Sets input image path
148
*
@@ -245,9 +307,14 @@ class EasyWatermark
245
*
246
* @return array settings
247
*/
248
- private function parseSettings(){
249
- // merge with defaults
250
- $settings = array_merge($this->defaultSettings, $this->settings);
251
252
if(strpos($settings['offset_x'], '%') === (strlen($settings['offset_x']) - 1)){
253
$settings['offset_x'] = substr($settings['offset_x'], 0, strlen($settings['offset_x']) - 1);
@@ -300,6 +367,17 @@ class EasyWatermark
300
break;
301
}
302
303
return $settings;
304
}
305
@@ -308,11 +386,31 @@ class EasyWatermark
308
*/
309
private $inputImage;
310
311
/**
312
* @var resource GD image created from watermark file
313
*/
314
private $watermarkImage;
315
316
/**
317
* @var resource GD image prepared as output
318
*/
@@ -335,132 +433,215 @@ class EasyWatermark
335
* @param string output file mime
336
* @return boolean
337
*/
338
- public function create($imagePath = null, $imageMime = null,
339
- $watermarkPath = null, $watermarkMime = null){
340
-
341
- if(empty($imagePath)) $imagePath = $this->imagePath;
342
- if(empty($imageMime)) $imageMime = $this->imageMime;
343
- if(empty($watermarkPath)) $watermarkPath = $this->watermarkPath;
344
- if(empty($watermarkMime)) $watermarkMime = $this->watermarkMime;
345
-
346
- if(!empty($imagePath) && !empty($watermarkPath)){
347
- if($imagePath != $watermarkPath){
348
- // Create GD image resources
349
- list($this->inputImage, $inputType) = $this->createImage($imagePath, $imageMime);
350
- list($this->watermarkImage, $wmType) = $this->createImage($watermarkPath, $watermarkMime);
351
-
352
- if(!$this->inputImage || !$this->watermarkImage)
353
- return false;
354
-
355
- // Prepare settings array
356
- $settings = $this->parseSettings();
357
-
358
- // Get image dimensions
359
- $imageWidth = imagesx($this->inputImage);
360
- $imageHeight = imagesy($this->inputImage);
361
-
362
- // Get watermark dimensions
363
- $watermarkWidth = imagesx($this->watermarkImage);
364
- $watermarkHeight = imagesy($this->watermarkImage);
365
-
366
- // Compute watermark offset
367
- $offsetX = $this->computeOffset($settings['position_x'], $settings['offset_x'],
368
- $imageWidth, $watermarkWidth, $settings['offset_x_pc']);
369
- $offsetY = $this->computeOffset($settings['position_y'], $settings['offset_y'],
370
- $imageHeight, $watermarkHeight, $settings['offset_y_pc']);
371
-
372
- // Create blank image
373
- $this->outputImage = imagecreatetruecolor($imageWidth, $imageHeight);
374
-
375
- imagecopy($this->outputImage, $this->inputImage,
376
- 0, 0, 0, 0, $imageWidth, $imageHeight
377
- );
378
-
379
- // Prepare params for copying function
380
- $params = array($this->outputImage, $this->watermarkImage,
381
- $offsetX, $offsetY,
382
- 0, 0,
383
- $watermarkWidth, $watermarkHeight
384
- );
385
- if($wmType == 'png' && $this->isAlphaPng($watermarkPath)){
386
- // Watermark is PNG with alpha channel, use imagecopy
387
- $func = 'imagecopy';
388
}
389
else {
390
- // Use imagecopymerge with opacity param for other images
391
- $func = 'imagecopymerge';
392
- $params[] = $settings['opacity'];
393
}
394
395
- // Copy watermark to output image
396
- call_user_func_array($func, $params);
397
-
398
- return true;
399
}
400
- else {
401
- $this->error = 'same image and watermark paths';
402
}
403
}
404
else {
405
- $this->error = empty($imagePath) ? 'empty image path' : 'empty watermark path';
406
}
407
408
- return false;
409
}
410
411
/**
412
- * Prints created image directly to the browser
413
*
414
* @return boolean
415
*/
416
- public function printOutput(){
417
- return $this->prepareOutput();
418
}
419
420
/**
421
- * Saves created image
422
*
423
- * @param string filename (required if not set earlier)
424
* @return boolean
425
*/
426
- public function saveOutput($file = null){
427
- if(empty($file)) $file = $this->outputFile;
428
429
- if(empty($file)){
430
- $this->error = 'output file not defined';
431
- return false;
432
}
433
434
- return $this->prepareOutput($file);
435
}
436
437
/**
438
- * Saves or outputs created image depending on $output param
439
*
440
- * @param string output file
441
- * @return boolean
442
*/
443
- private function prepareOutput($output = null){
444
- $type = !empty($this->outputMime) ? $this->detectMimeType($this->outputMime) : $this->inputImage[1];
445
446
- if(!$type || !in_array($type, $this->allowedTypes)){
447
- $this->error = 'invalid output type';
448
- return false;
449
}
450
451
- if($output === null)
452
- // Return image directly to the browser
453
- header('Content-Type: image/'.$type);
454
455
- if($type == 'jpg') $type = 'jpeg';
456
- $func = 'image'.$type;
457
458
- if(!@$func($this->outputImage, $output)){
459
- $this->error = 'could not create output';
460
- return false;
461
}
462
463
- return true;
464
}
465
466
/**
@@ -519,6 +700,61 @@ class EasyWatermark
519
return array($image, $type);
520
}
521
522
/**
523
* Detects mime type using php finfo object and extracts what's needed
524
*
1
<?php
2
/**
3
* @package Easy Watermark
4
+ * @version 2.0
5
* @license GPL
6
* @author Wojtek Szałkiewicz
7
* @author url http://szalkiewicz.pl
32
* You can also specify custom output format, and save it as file using saveOutput method.
33
* TODO:
34
* - watermark scaling
35
* Any other ideas, pleas contact me.
36
*/
37
+ namespace szaleq\Plugins\EasyWatermark;
38
+ /* Namespace is only needed for WP plugin, can be removed or changed if using this class separately. */
39
40
class EasyWatermark
41
{
43
* @var array default settings
44
*/
45
private $defaultSettings = array(
46
+ 'image' => array(
47
+ 'position_x' => 2,
48
+ 'position_y' => 2,
49
+ 'offset_x' => 0,
50
+ 'offset_y' => 0,
51
+ 'opacity' => 100
52
+ ),
53
+ 'text' => array(
54
+ 'position_x' => 2,
55
+ 'position_y' => 2,
56
+ 'offset_x' => 0,
57
+ 'offset_y' => 0,
58
+ 'opacity' => 60,
59
+ 'color' => 'fff',
60
+ 'font' => '',
61
+ 'size' => 24,
62
+ 'angle' => 0,
63
+ 'text' => ''
64
+ )
65
);
66
67
/**
99
*/
100
private $outputMime = '';
101
102
+ /**
103
+ * @var string watermark text
104
+ */
105
+ private $text = '';
106
+
107
/**
108
* @var string error message
109
*/
114
*
115
* @param array settings
116
*/
117
+ public function __construct($imageSettings = array(), $textSettings = array()){
118
+ $this->imageSet($imageSettings);
119
+ $this->textSet($textSettings);
120
}
121
122
/**
123
+ * Sets watermark image parameters
124
*
125
* @see $defaultSettings
126
* @chainable
128
* @param string value
129
* @return object $this
130
*/
131
+ public function imageSet($key, $val = null){
132
if(is_array($key)){
133
// act recursive
134
foreach($key as $k => $v){
135
+ $this->imageSet($k, $v);
136
}
137
return $this;
138
}
157
$this->setOutputMime($val);
158
break;
159
default:
160
+ $this->settings['image'][$key] = $val;
161
break;
162
}
163
164
return $this;
165
}
166
167
+ /**
168
+ * Sets watermark text parameters
169
+ *
170
+ * @see $defaultSettings
171
+ * @chainable
172
+ * @param string settings key
173
+ * @param string value
174
+ * @return object $this
175
+ */
176
+ public function textSet($key, $val = null){
177
+ if(is_array($key)){
178
+ // act recursive
179
+ foreach($key as $k => $v){
180
+ $this->textSet($k, $v);
181
+ }
182
+ return $this;
183
+ }
184
+
185
+ if($key == 'text'){
186
+ $this->setText($val);
187
+ }
188
+ else {
189
+ $this->settings['text'][$key] = $val;
190
+ }
191
+
192
+ return $this;
193
+ }
194
+
195
+ /**
196
+ * Sets watermark text
197
+ *
198
+ * @chainable
199
+ * @param string watermark text
200
+ * @return object $this
201
+ */
202
+ public function setText($value){
203
+ $this->text = $value;
204
+
205
+ return $this;
206
+ }
207
+
208
/**
209
* Sets input image path
210
*
307
*
308
* @return array settings
309
*/
310
+ private function parseSettings($section){
311
+
312
+ if(!isset($this->defaultSettings[$section]))
313
+ return false;
314
+
315
+ $settings = isset($this->settings[$section]) ?
316
+ array_merge($this->defaultSettings[$section], $this->settings[$section]) :
317
+ $this->defaultSettings[$section];
318
319
if(strpos($settings['offset_x'], '%') === (strlen($settings['offset_x']) - 1)){
320
$settings['offset_x'] = substr($settings['offset_x'], 0, strlen($settings['offset_x']) - 1);
367
break;
368
}
369
370
+ if(isset($settings['color'])){
371
+ if(strpos($settings['color'], '#') === 0){
372
+ $settings['color'] = substr($settings['color'], 1);
373
+ }
374
+ if(strlen($settings['color']) == 3){
375
+ $settings['color'] = $settings['color'][0].$settings['color'][0].
376
+ $settings['color'][1].$settings['color'][1].
377
+ $settings['color'][2].$settings['color'][2];
378
+ }
379
+ }
380
+
381
return $settings;
382
}
383
386
*/
387
private $inputImage;
388
389
+ /**
390
+ * @var string image type
391
+ */
392
+ private $inputImageType;
393
+
394
+ /**
395
+ * @var array image size
396
+ */
397
+ private $imageSize;
398
+
399
/**
400
* @var resource GD image created from watermark file
401
*/
402
private $watermarkImage;
403
404
+ /**
405
+ * @var string image type
406
+ */
407
+ private $watermarkImageType;
408
+
409
+ /**
410
+ * @var array watermark size
411
+ */
412
+ private $watermarkSize;
413
+
414
/**
415
* @var resource GD image prepared as output
416
*/
433
* @param string output file mime
434
* @return boolean
435
*/
436
+ public function create(){
437
+
438
+ $return = false;
439
+ if(!empty($this->imagePath)){
440
+ if(!empty($this->watermarkPath)){
441
+ if($this->imagePath != $this->watermarkPath){
442
+ $this->applyImageWatermark();
443
+ $return = true;
444
}
445
else {
446
+ $this->error = 'Same image and watermark paths';
447
}
448
+ }
449
450
+ if(!empty($this->text)){
451
+ $this->applyTextWatermark();
452
+ $return = true;
453
}
454
+
455
+ if(!$return){
456
+ $this->error = 'No watermark image and no text specified';
457
}
458
}
459
else {
460
+ $this->error = 'Input image not specified';
461
}
462
463
+ return $return;
464
}
465
466
/**
467
+ * Creates output image with watermarm
468
*
469
* @return boolean
470
*/
471
+ public function applyImageWatermark(){
472
+
473
+ $this->getInputImage();
474
+ $this->getOutputImage();
475
+
476
+ // Create GD image resources
477
+ list($this->watermarkImage, $this->watermarkImageType) = $this->createImage($this->watermarkPath, $this->watermarkMime);
478
+
479
+ if(!$this->inputImage || !$this->watermarkImage)
480
+ return false;
481
+
482
+ // Prepare settings array
483
+ $settings = $this->parseSettings('image');
484
+
485
+ // Get image dimensions
486
+ list($imageWidth, $imageHeight) = $this->getImageSize();
487
+
488
+ // Get watermark dimensions
489
+ list($watermarkWidth, $watermarkHeight) = $this->getWatermarkSize();
490
+
491
+ // Compute watermark offset
492
+ $offsetX = $this->computeOffset($settings['position_x'], $settings['offset_x'],
493
+ $imageWidth, $watermarkWidth, $settings['offset_x_pc']);
494
+ $offsetY = $this->computeOffset($settings['position_y'], $settings['offset_y'],
495
+ $imageHeight, $watermarkHeight, $settings['offset_y_pc']);
496
+
497
+ // Prepare params for copying function
498
+ $params = array($this->outputImage, $this->watermarkImage,
499
+ $offsetX, $offsetY,
500
+ 0, 0,
501
+ $watermarkWidth, $watermarkHeight
502
+ );
503
+ if($this->watermarkImageType == 'png' && $this->isAlphaPng($this->watermarkPath)){
504
+ // Watermark is PNG with alpha channel, use imagecopy
505
+ $func = 'imagecopy';
506
+ }
507
+ else {
508
+ // Use imagecopymerge with opacity param for other images
509
+ $func = 'imagecopymerge';
510
+ $params[] = $settings['opacity'];
511
+ }
512
+
513
+ // Copy watermark to output image
514
+ call_user_func_array($func, $params);
515
+
516
+ return true;
517
}
518
519
/**
520
+ * Adds text watermark to output image
521
*
522
* @return boolean
523
*/
524
+ public function applyTextWatermark(){
525
526
+ $this->getInputImage();
527
+ $this->getOutputImage();
528
+
529
+ $settings = $this->parseSettings('text');
530
+
531
+ list($textWidth, $textHeight, $deltaX, $deltaY) = $this->getTextSize($settings['size'], $settings['angle'], $settings['font'], $this->text);
532
+ list($imageWidth, $imageHeight) = $this->getImageSize();
533
+
534
+ $color = $settings['color'];
535
+ $color = imagecolorallocatealpha($this->outputImage,
536
+ hexdec(substr($color, 0, 2)),
537
+ hexdec(substr($color, 2, 2)),
538
+ hexdec(substr($color, 4, 2)),
539
+ 127 * (100 - $settings['opacity']) / 100);
540
+
541
+ // Compute watermark offset
542
+ $offsetX = $this->computeOffset($settings['position_x'], $settings['offset_x'],
543
+ $imageWidth, $textWidth, $settings['offset_x_pc']);
544
+ $offsetY = $this->computeOffset($settings['position_y'], $settings['offset_y'],
545
+ $imageHeight, $textHeight, $settings['offset_y_pc']);
546
+
547
+ imagettftext($this->outputImage,
548
+ $settings['size'],
549
+ $settings['angle'],
550
+ $offsetX - $deltaX, $offsetY - $deltaY,
551
+ $color,
552
+ $settings['font'],
553
+ $this->text);
554
+
555
+ return true;
556
+ }
557
+
558
+ /**
559
+ * Returns size of text bounding box width x and y distance from font baseline
560
+ *
561
+ * @param integer font size
562
+ * @param integer angle
563
+ * @param string font file path
564
+ * @param string text
565
+ * @return array
566
+ */
567
+ private function getTextSize($fontSize, $angle, $font, $text){
568
+
569
+ $bb = imagettfbbox($fontSize, $angle, $font, $text);
570
+
571
+ $maxX = max($bb[0], $bb[2], $bb[4], $bb[6]);
572
+ $minX = min($bb[0], $bb[2], $bb[4], $bb[6]);
573
+ $x = $maxX - $minX;
574
+
575
+ $maxY = max($bb[1], $bb[3], $bb[5], $bb[7]);
576
+ $minY = min($bb[1], $bb[3], $bb[5], $bb[7]);
577
+ $y = $maxY - $minY;
578
+
579
+ return array($x, $y, $minX, $minY);
580
+ }
581
+
582
+ /**
583
+ * Creates if not exist and returns input image
584
+ *
585
+ * @return resource GD image
586
+ */
587
+ private function getInputImage(){
588
+ if(empty($this->inputImage)){
589
+ list($this->inputImage, $this->inputImageType) = $this->createImage($this->imagePath, $this->imageMime);
590
}
591
592
+ return $this->inputImage;
593
}
594
595
/**
596
+ * Creates if not exist and returns output image
597
*
598
+ * @return resource GD image
599
*/
600
+ private function getOutputImage(){
601
+ if(empty($this->outputImage)){
602
+ list($imageWidth, $imageHeight) = $this->getImageSize();
603
604
+ // Create blank image
605
+ $this->outputImage = imagecreatetruecolor($imageWidth, $imageHeight);
606
+
607
+ imagecopy($this->outputImage, $this->inputImage,
608
+ 0, 0, 0, 0, $imageWidth, $imageHeight
609
+ );
610
}
611
612
+ return $this->outputImage;
613
+ }
614
615
+ /**
616
+ * Returns input image size
617
+ *
618
+ * @return array width and height
619
+ */
620
+ private function getImageSize(){
621
+ if(empty($this->imageSize)){
622
+ $this->imageSize = array(
623
+ imagesx($this->inputImage),
624
+ imagesy($this->inputImage)
625
+ );
626
+ }
627
628
+ return $this->imageSize;
629
+ }
630
+
631
+ /**
632
+ * Returns watermark image size
633
+ *
634
+ * @return array width and height
635
+ */
636
+ private function getWatermarkSize(){
637
+ if(empty($this->watermarkSize)){
638
+ $this->watermarkSize = array(
639
+ imagesx($this->watermarkImage),
640
+ imagesy($this->watermarkImage)
641
+ );
642
}
643
644
+ return $this->watermarkSize;
645
}
646
647
/**
700
return array($image, $type);
701
}
702
703
+ /**
704
+ * Prints created image directly to the browser
705
+ *
706
+ * @return boolean
707
+ */
708
+ public function printOutput(){
709
+ return $this->prepareOutput();
710
+ }
711
+
712
+ /**
713
+ * Saves created image
714
+ *
715
+ * @param string filename (required if not set earlier)
716
+ * @return boolean
717
+ */
718
+ public function saveOutput($file = null){
719
+ if(empty($file)) $file = $this->outputFile;
720
+
721
+ if(empty($file)){
722
+ $this->error = 'output file not defined';
723
+ return false;
724
+ }
725
+
726
+ return $this->prepareOutput($file);
727
+ }
728
+
729
+ /**
730
+ * Saves or outputs created image depending on $output param
731
+ *
732
+ * @param string output file
733
+ * @return boolean
734
+ */
735
+ private function prepareOutput($output = null){
736
+ $type = !empty($this->outputMime) ? $this->detectMimeType($this->outputMime) : $this->inputImageType;
737
+
738
+ if(!$type || !in_array($type, $this->allowedTypes)){
739
+ $this->error = 'invalid output type';
740
+ return false;
741
+ }
742
+
743
+ if($output === null)
744
+ // Return image directly to the browser
745
+ header('Content-Type: image/'.$type);
746
+
747
+ if($type == 'jpg') $type = 'jpeg';
748
+ $func = 'image'.$type;
749
+
750
+ if(!@$func($this->outputImage, $output)){
751
+ $this->error = 'could not create output';
752
+ return false;
753
+ }
754
+
755
+ return true;
756
+ }
757
+
758
/**
759
* Detects mime type using php finfo object and extracts what's needed
760
*
EasyWatermarkPlugin.php CHANGED
@@ -1,40 +1,35 @@
1
<?php
2
/**
3
- This file is a part of EasyWatermark Wordpress plugin.
4
- For license informations, author name etc. see readme.txt
5
- */
6
7
/**
8
* Main plugin class
9
*/
10
-
11
- class EasyWatermarkPlugin
12
{
13
- private static $version = '0.1.1';
14
-
15
- private $settings;
16
-
17
- private $messages = array();
18
19
- private $allowedMime = array('image/png', 'image/jpeg', 'image/gif');
20
21
/**
22
- * Initiate plugin by creating self object,
23
- * registers activation and uninstall hooks
24
- *
25
- * @return void
26
*/
27
- public static function init(){
28
- register_activation_hook(__FILE__, array(self, 'install'));
29
- register_uninstall_hook(__FILE__, array(self, 'uninstall'));
30
31
- $version = get_option('easy-watermark-version');
32
- if(!$version || version_compare($version, self::$version, '<')){
33
- self::upgrade();
34
- }
35
36
- new self();
37
- }
38
39
/**
40
* Loads textdomain for translations,
@@ -42,15 +37,18 @@ class EasyWatermarkPlugin
42
*
43
* @return void
44
*/
45
- private function __construct(){
46
- load_plugin_textdomain('easy-watermark', false, '/easy-watermark/languages');
47
48
- add_action('admin_menu', array($this, 'add_media_page'));
49
- add_filter('media_row_actions', array($this, 'add_media_row_action'), 10, 3);
50
- add_filter('attachment_fields_to_edit', array($this, 'add_attachment_field'), 10, 2 );
51
- add_action('add_attachment', array($this, 'add_watermark_after_upload'));
52
53
- $this->settings = new EasyWatermarkSettings();
54
}
55
56
/**
@@ -96,19 +94,46 @@ class EasyWatermarkPlugin
96
}
97
98
/**
99
- * Creates 'Add watermark' button in media edit view
100
*
101
* @return array
102
*/
103
public function add_watermark_after_upload($id){
104
- if($this->settings->get('auto_add')){
105
$this->add_watermark($id);
106
}
107
}
108
109
private function add_watermark($id){
110
- $watermark = $this->settings->get('image');
111
- if($watermark['path'] != ''){
112
$post = get_post($id);
113
$filepath = get_attached_file($id);
114
@@ -120,7 +145,7 @@ class EasyWatermarkPlugin
120
return $this->create_watermark($filepath, $post->post_mime_type);
121
}
122
else {
123
- $this->add_error('No watermark image selected.');
124
return false;
125
}
126
}
@@ -136,20 +161,20 @@ class EasyWatermarkPlugin
136
");
137
138
$output = '';
139
- $watermark = $this->settings->get('image');
140
- if($images && $watermark['path'] != ''){
141
foreach($images as $img){
142
$filepath = get_attached_file($img->ID);
143
if(!in_array($img->post_mime_type, $this->allowedMime)){
144
- $output .= $filepath.': not supported mime type. Skipping...<br/>';
145
continue;
146
}
147
148
if($this->create_watermark($filepath, $img->post_mime_type)){
149
- $output .= $filepath.': watermark added.<br/>';
150
}
151
}
152
}
153
154
$output = '<p>'.$output.'</p>';
155
@@ -175,11 +200,19 @@ class EasyWatermarkPlugin
175
176
public function getEasyWatermark(){
177
if(!($ew instanceof EasyWatermark)){
178
- $settings = $this->settings->get('image');
179
$ew = new EasyWatermark();
180
- $ew->set($settings)
181
- ->set('watermark_path', $settings['path'])
182
- ->set('watermark_mime', $settings['mime']);
183
}
184
185
return $ew;
@@ -195,7 +228,7 @@ class EasyWatermarkPlugin
195
if($this->add_watermark($_GET['attachment_id'])) :
196
?>
197
<div id="message" class="updated below-h2">
198
- <p><?php _e('Watermark successfully added.', 'easy-watermark'); ?> <a href="javascript:window.history.go(-1)"><?php _e('Go back', 'easy-watermark'); ?></a> or <a href="<?php echo get_edit_post_link($_GET['attachment_id']); ?>"><?php _e('go to edit page', 'easy-watermark'); ?></a></p>
199
</div>
200
<?php
201
else :
@@ -224,41 +257,81 @@ class EasyWatermarkPlugin
224
?>
225
<br/><a class="button-primary" href="<?php echo wp_nonce_url(admin_url('/upload.php?page=easy-watermark&watermark_all=1')); ?>"><?php _e('Add watermark to all images', 'easy-watermark'); ?></a><p class="description"><?php _e('Be carefull with that option. If some images alredy has watermark, it will be added though.'); ?></p>
226
<?php
227
- $settings = $this->settings->get('image');
228
}
229
?>
230
</div>
231
<?php
232
}
233
234
- public static function install(){
235
- add_option('easy-watermark-settings', EasyWatermarkSettings::getDefaults());
236
- update_option('easy-watermark-version', self::$version);
237
}
238
239
public static function uninstall(){
240
- delete_option('easy-watermark-settings');
241
}
242
243
- public static function upgrade(){
244
- $oldSettings = get_option('easy-watermark-settings');
245
- $settings = EasyWatermarkSettings::getDefaults();
246
247
- $settings['auto_add'] = $oldSettings['auto_add'];
248
- $settings['image_types'] = $oldSettings['image_types'];
249
- $settings['image']['position_x'] = $oldSettings['image']['position-horizontal'];
250
- $settings['image']['position_y'] = $oldSettings['image']['position-vert'];
251
- $settings['image']['offset_x'] = $oldSettings['image']['offset-horizontal'];
252
- $settings['image']['offset_y'] = $oldSettings['image']['offset-vert'];
253
- $settings['image']['opacity'] = $oldSettings['image']['alpha'];
254
-
255
- foreach($oldSettings['image'] as $key => $val){
256
- if(array_key_exists($key, $settings['image']))
257
- $settings['image'][$key] = $val;
258
}
259
260
- update_option('easy-watermark-settings', $settings);
261
- update_option('easy-watermark-version', self::$version);
262
}
263
264
private function add_error($msg){
1
<?php
2
/**
3
+ * This file is a part of EasyWatermark Wordpress plugin.
4
+ * @see readme.txt
5
+ */
6
+ namespace szaleq\Plugins\EasyWatermark;
7
8
/**
9
* Main plugin class
10
*/
11
+ class Plugin extends Core
12
{
13
+ /**
14
+ * @var string plugin name
15
+ */
16
+ protected static $pluginName = 'Easy Watermark';
17
18
+ /**
19
+ * @var string plugin slug used in setting names etc.
20
+ */
21
+ protected static $pluginSlug = 'easy-watermark';
22
23
/**
24
+ * @var string plugin version
25
*/
26
+ protected static $version = '0.2';
27
28
+ private $settings;
29
30
+ private $messages = array();
31
+
32
+ private $allowedMime = array('image/png', 'image/jpeg', 'image/gif');
33
34
/**
35
* Loads textdomain for translations,
37
*
38
* @return void
39
*/
40
+ public function __construct(){
41
42
+ $this->add_action('admin_menu', 'add_media_page')
43
+ ->add_filter('media_row_actions', 'add_media_row_action', 10, 3)
44
+ ->add_filter('attachment_fields_to_edit', 'add_attachment_field', 10, 2)
45
+ ->add_action('add_attachment', 'add_watermark_after_upload');
46
+
47
+ new EasyWatermarkSettings($this);
48
+ }
49
50
+ public function setSettings($settings){
51
+ $this->settings = $settings;
52
}
53
54
/**
94
}
95
96
/**
97
+ * Watermark image after it was uploaded.
98
+ * In fact this method only mark that there is an image to watermark,
99
+ * it's realy watermarked in wp_generate_attachment_metadata filter.
100
+ * See wp_generate_attachment_metadata() method below.
101
*
102
* @return array
103
*/
104
public function add_watermark_after_upload($id){
105
+ if($this->settings['general']['auto_add']){
106
+ $this->watermark_uploaded = true;
107
+ $this->uploaded_id = $id;
108
+ $this->add_filter('wp_generate_attachment_metadata', null, 10, 2);
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Filter used to add watermark
114
+ * add_attachment action is called before image resizing,
115
+ * so image was watermarked first, then resized.
116
+ * To avoid that, in add_attachment action we only mark,
117
+ * that image was uploaded and then it's watermarked in this filter
118
+ * which is called after resizing.
119
+ *
120
+ * @param array
121
+ * @param integer
122
+ * @return array
123
+ */
124
+ public function wp_generate_attachment_metadata($metadata, $id){
125
+ if($this->watermark_uploaded && $this->uploaded_id == $id){
126
$this->add_watermark($id);
127
+
128
+ $this->watermark_uploaded = false;
129
+ $this->uploaded_id = null;
130
}
131
+
132
+ return $metadata;
133
}
134
135
private function add_watermark($id){
136
+ if($this->settings['image']['watermark_path'] != '' || $this->settings['text']['text'] == null){
137
$post = get_post($id);
138
$filepath = get_attached_file($id);
139
145
return $this->create_watermark($filepath, $post->post_mime_type);
146
}
147
else {
148
+ $this->add_error('No watermark image selected and no watermark text set.');
149
return false;
150
}
151
}
161
");
162
163
$output = '';
164
+ if($images && ($this->settings['image']['watermark_path'] != '' || $this->settings['text']['text'])){
165
foreach($images as $img){
166
$filepath = get_attached_file($img->ID);
167
if(!in_array($img->post_mime_type, $this->allowedMime)){
168
+ $output .= sprintf(__('Not supported mime type of %s. Skipping...', 'easy-watermark'), '<strong>'.$filepath.'</strong>').'<br/>';
169
continue;
170
}
171
172
if($this->create_watermark($filepath, $img->post_mime_type)){
173
+ $output .= sprintf(__('Watermark successfully added to %s', 'easy-watermark'), '<strong>'.$filepath.'</strong>') . '<br/>';
174
}
175
}
176
}
177
+ else return false;
178
179
$output = '<p>'.$output.'</p>';
180
200
201
public function getEasyWatermark(){
202
if(!($ew instanceof EasyWatermark)){
203
+ $imageSettings = $this->settings['image'];
204
+ $textSettings = $this->settings['text'];
205
$ew = new EasyWatermark();
206
+
207
+ $fontFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $textSettings['font'];
208
+ if(file_exists($fontFile))
209
+ $textSettings['font'] = $fontFile;
210
+
211
+ $wType = $this->settings['general']['watermark_type'];
212
+ if($wType == 1 || $wType == 3)
213
+ $ew->imageSet($imageSettings);
214
+ if($wType == 2 || $wType == 3)
215
+ $ew->textSet($textSettings);
216
}
217
218
return $ew;
228
if($this->add_watermark($_GET['attachment_id'])) :
229
?>
230
<div id="message" class="updated below-h2">
231
+ <p><?php _e('Watermark successfully added.', 'easy-watermark'); ?> <a href="javascript:window.history.go(-1)"><?php _e('Go back', 'easy-watermark'); ?></a> <?php _e('or', 'easy-watermark'); ?> <a href="<?php echo get_edit_post_link($_GET['attachment_id']); ?>"><?php _e('go to edit page', 'easy-watermark'); ?></a></p>
232
</div>
233
<?php
234
else :
257
?>
258
<br/><a class="button-primary" href="<?php echo wp_nonce_url(admin_url('/upload.php?page=easy-watermark&watermark_all=1')); ?>"><?php _e('Add watermark to all images', 'easy-watermark'); ?></a><p class="description"><?php _e('Be carefull with that option. If some images alredy has watermark, it will be added though.'); ?></p>
259
<?php
260
}
261
?>
262
</div>
263
<?php
264
}
265
266
+ public static function install($settings = null){
267
+ if(empty($settings)) $settings = EasyWatermarkSettings::getDefaults();
268
+
269
+ foreach($settings as $sectionName => $section){
270
+ update_option(static::$pluginSlug.'-settings-'.$sectionName, $section);
271
+ }
272
+ update_option(static::$pluginSlug.'-version', static::$version);
273
}
274
275
public static function uninstall(){
276
+ $settings = EasyWatermarkSettings::getDefaults();
277
+
278
+ foreach($settings as $sectionName => $section){
279
+ delete_option(static::$pluginSlug.'-settings-'.$sectionName);
280
+ }
281
+ delete_option(static::$pluginSlug.'-version');
282
}
283
284
+ public static function upgrade($version){
285
+ $oldSettings = get_option(static::$pluginSlug.'-settings');
286
+ $defaults = EasyWatermarkSettings::getDefaults();
287
288
+ $imgTypes = array();
289
+ foreach($oldSettings['image_types'] as $type){
290
+ $imgTypes[] = $type;
291
}
292
293
+ $general = array(
294
+ 'auto_add' => $oldSettings['auto_add'],
295
+ 'image_types' => $imgTypes
296
+ );
297
+
298
+ switch($version){
299
+ case '0.1.1':
300
+ $image = array(
301
+ 'watermark_url' => $oldSettings['image']['url'],
302
+ 'watermark_id' => $oldSettings['image']['id'],
303
+ 'watermark_path' => $oldSettings['image']['path'],
304
+ 'watermark_mime' => $oldSettings['image']['mime'],
305
+ 'position_x' => $oldSettings['image']['position_x'],
306
+ 'position_y' => $oldSettings['image']['position_y'],
307
+ 'offset_x' => $oldSettings['image']['offset_x'],
308
+ 'offset_y' => $oldSettings['image']['offset_y'],
309
+ 'opacity' => $oldSettings['image']['opacity']
310
+ );
311
+ break;
312
+ default:
313
+ $image = array(
314
+ 'watermark_url' => $oldSettings['image']['url'],
315
+ 'watermark_id' => $oldSettings['image']['id'],
316
+ 'watermark_path' => $oldSettings['image']['path'],
317
+ 'watermark_mime' => $oldSettings['image']['mime'],
318
+ 'position_x' => $oldSettings['image']['position-horizontal'],
319
+ 'position_y' => $oldSettings['image']['position-vert'],
320
+ 'offset_x' => $oldSettings['image']['offset-horizontal'],
321
+ 'offset_y' => $oldSettings['image']['offset-vert'],
322
+ 'opacity' => $oldSettings['image']['alpha']
323
+ );
324
+ break;
325
+ }
326
+
327
+ $settings = array(
328
+ 'general' => array_merge($defaults['general'], $general),
329
+ 'image' => array_merge($defaults['image'], $image),
330
+ 'text' => $defaults['text']
331
+ );
332
+
333
+ delete_option(static::$pluginSlug.'-settings');
334
+ static::install($settings);
335
}
336
337
private function add_error($msg){
EasyWatermarkSettings.php CHANGED
@@ -1,39 +1,80 @@
1
<?php
2
3
class EasyWatermarkSettings
4
{
5
- private $tabs = array();
6
7
- private $options = array();
8
9
private static $defaults = array(
10
'auto_add' => true,
11
- 'image_types' => array('jpeg' => 'jpeg', 'png' => 'png', 'gif' => 'gif'),
12
- 'image' => array(
13
- 'url' => null,
14
- 'path' => null,
15
- 'id' => null,
16
- 'mime' => null,
17
- 'position_x' => 'ctr',
18
- 'position_y' => 'mdl',
19
- 'offset_x' => 100,
20
- 'offset_y' => 100,
21
- 'opacity' => 100,
22
- )
23
- );
24
25
public static function getDefaults(){
26
return self::$defaults;
27
}
28
29
- public function __construct(){
30
31
add_action('admin_menu', array($this, 'add_options_page'));
32
add_action('admin_init', array($this, 'register_settings'));
33
-
34
add_filter('plugin_action_links', array($this, 'settings_link'), 10, 2);
35
36
- $this->options = get_option('easy-watermark-settings');
37
}
38
39
public function get($key){
@@ -41,18 +82,20 @@ class EasyWatermarkSettings
41
}
42
43
public function add_options_page(){
44
- add_options_page(__('Easy Watermark Settings', 'easy-watermark'), __('Easy Watermark Settings', 'easy-watermark'), 'manage_options', 'easy-watermark-settings', array($this, 'settings_page'));
45
}
46
47
public function register_settings(){
48
- register_setting(
49
- 'easy-watermark-settings',
50
- 'easy-watermark-settings',
51
- array($this, 'sanitize_settings')
52
- );
53
}
54
55
- public function sanitize_settings($input){
56
if(!isset($input['auto_add']) || $input['auto_add'] !== '1'){
57
$input['auto_add'] = false;
58
}
@@ -61,7 +104,14 @@ class EasyWatermarkSettings
61
$input['image_types'] = array();
62
}
63
64
- if(!empty($input['image']['url'])){
65
if(isset($input['old-manager'])){
66
// old wordpress media library, we have only image url
67
global $wpdb;
@@ -73,21 +123,25 @@ class EasyWatermarkSettings
73
AND $wpdb->posts.guid = '{$input['image']['url']}'
74
");
75
76
- $input['image']['id'] = $row->ID;
77
- $input['image']['mime'] = $row->post_mime_type;
78
unset($input['old-manager']);
79
}
80
81
- $input['image']['path'] = get_attached_file($input['image']['id']);
82
}
83
84
- $input = wp_parse_args($input, $this->options);
85
-
86
return $input;
87
}
88
89
public function settings_page(){
90
wp_enqueue_script('ew-interface', plugin_dir_url(dirname(__File__) . '/index.php') . 'js/interface.js');
91
if(function_exists('wp_enqueue_media')){
92
// load new media manager (since wp 3.5)
93
wp_enqueue_media();
@@ -100,7 +154,10 @@ class EasyWatermarkSettings
100
wp_enqueue_script('ew-media-libraby', plugin_dir_url(dirname(__File__) . '/index.php') . 'js/old-media-library.js');
101
}
102
103
- $options = $this->options;
104
include dirname(__File__) . '/settings-form.php';
105
}
106
1
<?php
2
+ namespace szaleq\Plugins\EasyWatermark;
3
4
class EasyWatermarkSettings
5
{
6
+ private $settings = array();
7
8
+ private $plugin;
9
10
private static $defaults = array(
11
+ 'general' => array(
12
'auto_add' => true,
13
+ 'image_types' => array('jpeg', 'png', 'gif'),
14
+ 'watermark_type' => 3
15
+ ),
16
+ 'image' => array(
17
+ 'watermark_url' => null,
18
+ 'watermark_id' => null,
19
+ 'watermark_path' => null,
20
+ 'watermark_mime' => null,
21
+ 'position_x' => 'ctr',
22
+ 'position_y' => 'mdl',
23
+ 'offset_x' => 100,
24
+ 'offset_y' => 100,
25
+ 'opacity' => 100
26
+ ),
27
+ 'text' => array(
28
+ 'position_x' => 'ctr',
29
+ 'position_y' => 'mdl',
30
+ 'offset_x' => 0,
31
+ 'offset_y' => 0,
32
+ 'opacity' => 60,
33
+ 'color' => '000000',
34
+ 'font' => 'arial',
35
+ 'size' => 24,
36
+ 'angle' => 0,
37
+ 'text' => ''
38
+ )
39
+ );
40
+
41
+ private $tabs = array(
42
+ 'general' => 'General',
43
+ 'image' => 'Image',
44
+ 'text' => 'Text',
45
+ );
46
+
47
+ private $fonts = array(
48
+ 'Arial.ttf' => 'Arial',
49
+ 'Arial_Black.ttf' => 'Arial Black',
50
+ 'Comic_Sans_MS.ttf' => 'Comic Sans MS',
51
+ 'Courier_New.ttf' => 'Courier New',
52
+ 'Georgia.ttf' => 'Georgia',
53
+ 'Impact.ttf' => 'Impact',
54
+ 'Tahoma.ttf' => 'Tahoma',
55
+ 'Times_New_Roman.ttf' => 'Times New Roman',
56
+ 'Trebuchet_MS.ttf' => 'Trebuchet MS',
57
+ 'Verdana.ttf' => 'Verdana',
58
+ );
59
60
public static function getDefaults(){
61
return self::$defaults;
62
}
63
64
+ public function __construct($plugin){
65
66
add_action('admin_menu', array($this, 'add_options_page'));
67
add_action('admin_init', array($this, 'register_settings'));
68
add_filter('plugin_action_links', array($this, 'settings_link'), 10, 2);
69
70
+ foreach($this->tabs as $name => $caption){
71
+ $section = get_option($plugin->getSlug() . '-settings-' . $name);
72
+ $this->settings[$name] = array_merge(self::$defaults[$name], $section);
73
+ }
74
+
75
+ $this->plugin = $plugin;
76
+
77
+ $plugin->setSettings($this->settings);
78
}
79
80
public function get($key){
82
}
83
84
public function add_options_page(){
85
+ add_options_page(__('Easy Watermark', 'easy-watermark'), __('Easy Watermark', 'easy-watermark'), 'manage_options', 'easy-watermark-settings', array($this, 'settings_page'));
86
}
87
88
public function register_settings(){
89
+ foreach($this->tabs as $name => $caption){
90
+ register_setting(
91
+ $this->plugin->getSlug() . '-settings-' . $name,
92
+ $this->plugin->getSlug() . '-settings-' . $name,
93
+ array($this, 'sanitize_settings_' . $name)
94
+ );
95
+ }
96
}
97
98
+ public function sanitize_settings_general($input){
99
if(!isset($input['auto_add']) || $input['auto_add'] !== '1'){
100
$input['auto_add'] = false;
101
}
104
$input['image_types'] = array();
105
}
106
107
+ $input = wp_parse_args($input, $this->options);
108
+
109
+ return $input;
110
+ }
111
+
112
+ public function sanitize_settings_image($input){
113
+
114
+ if(!empty($input['watermark_url'])){
115
if(isset($input['old-manager'])){
116
// old wordpress media library, we have only image url
117
global $wpdb;
123
AND $wpdb->posts.guid = '{$input['image']['url']}'
124
");
125
126
+ $input['watermark_id'] = $row->ID;
127
+ $input['watermark_mime'] = $row->post_mime_type;
128
unset($input['old-manager']);
129
}
130
131
+ $input['watermark_path'] = get_attached_file($input['watermark_id']);
132
}
133
+ return $input;
134
+ }
135
136
+ public function sanitize_settings_text($input){
137
return $input;
138
}
139
140
public function settings_page(){
141
+ wp_enqueue_script('ew-colorpicker', plugin_dir_url(dirname(__File__) . '/index.php') . 'js/colorpicker.js');
142
wp_enqueue_script('ew-interface', plugin_dir_url(dirname(__File__) . '/index.php') . 'js/interface.js');
143
+ wp_enqueue_style('ew-style', plugin_dir_url(dirname(__File__) . '/index.php') . 'css/style.css');
144
+ wp_enqueue_style('ew-cp-style', plugin_dir_url(dirname(__File__) . '/index.php') . 'css/colorpicker.css');
145
if(function_exists('wp_enqueue_media')){
146
// load new media manager (since wp 3.5)
147
wp_enqueue_media();
154
wp_enqueue_script('ew-media-libraby', plugin_dir_url(dirname(__File__) . '/index.php') . 'js/old-media-library.js');
155
}
156
157
+ $fonts = $this->fonts;
158
+
159
+ $current_tab = (isset($_GET['tab']) && array_key_exists($_GET['tab'], $this->tabs)) ? $_GET['tab'] : 'general';
160
+ extract($this->settings[$current_tab]);
161
include dirname(__File__) . '/settings-form.php';
162
}
163
css/colorpicker.css ADDED
@@ -0,0 +1,161 @@
1
+ .colorpicker {
2
+ width: 356px;
3
+ height: 176px;
4
+ overflow: hidden;
5
+ position: absolute;
6
+ background: url(../images/colorpicker_background.png);
7
+ font-family: Arial, Helvetica, sans-serif;
8
+ display: none;
9
+ }
10
+ .colorpicker_color {
11
+ width: 150px;
12
+ height: 150px;
13
+ left: 14px;
14
+ top: 13px;
15
+ position: absolute;
16
+ background: #f00;
17
+ overflow: hidden;
18
+ cursor: crosshair;
19
+ }
20
+ .colorpicker_color div {
21
+ position: absolute;
22
+ top: 0;
23
+ left: 0;
24
+ width: 150px;
25
+ height: 150px;
26
+ background: url(../images/colorpicker_overlay.png);
27
+ }
28
+ .colorpicker_color div div {
29
+ position: absolute;
30
+ top: 0;
31
+ left: 0;
32
+ width: 11px;
33
+ height: 11px;
34
+ overflow: hidden;
35
+ background: url(../images/colorpicker_select.gif);
36
+ margin: -5px 0 0 -5px;
37
+ }
38
+ .colorpicker_hue {
39
+ position: absolute;
40
+ top: 13px;
41
+ left: 171px;
42
+ width: 35px;
43
+ height: 150px;
44
+ cursor: n-resize;
45
+ }
46
+ .colorpicker_hue div {
47
+ position: absolute;
48
+ width: 35px;
49
+ height: 9px;
50
+ overflow: hidden;
51
+ background: url(../images/colorpicker_indic.gif) left top;
52
+ margin: -4px 0 0 0;
53
+ left: 0px;
54
+ }
55
+ .colorpicker_new_color {
56
+ position: absolute;
57
+ width: 60px;
58
+ height: 30px;
59
+ left: 213px;
60
+ top: 13px;
61
+ background: #f00;
62
+ }
63
+ .colorpicker_current_color {
64
+ position: absolute;
65
+ width: 60px;
66
+ height: 30px;
67
+ left: 283px;
68
+ top: 13px;
69
+ background: #f00;
70
+ }
71
+ .colorpicker input {
72
+ background-color: transparent;
73
+ border: 1px solid transparent;
74
+ position: absolute;
75
+ font-size: 10px;
76
+ font-family: Arial, Helvetica, sans-serif;
77
+ color: #898989;
78
+ top: 4px;
79
+ right: 11px;
80
+ text-align: right;
81
+ margin: 0;
82
+ padding: 0;
83
+ height: 11px;
84
+ }
85
+ .colorpicker_hex {
86
+ position: absolute;
87
+ width: 72px;
88
+ height: 22px;
89
+ background: url(../images/colorpicker_hex.png) top;
90
+ left: 212px;
91
+ top: 142px;
92
+ }
93
+ .colorpicker_hex input {
94
+ right: 6px;
95
+ }
96
+ .colorpicker_field {
97
+ height: 22px;
98
+ width: 62px;
99
+ background-position: top;
100
+ position: absolute;
101
+ }
102
+ .colorpicker_field span {
103
+ position: absolute;
104
+ width: 12px;
105
+ height: 22px;
106
+ overflow: hidden;
107
+ top: 0;
108
+ right: 0;
109
+ cursor: n-resize;
110
+ }
111
+ .colorpicker_rgb_r {
112
+ background-image: url(../images/colorpicker_rgb_r.png);
113
+ top: 52px;
114
+ left: 212px;
115
+ }
116
+ .colorpicker_rgb_g {
117
+ background-image: url(../images/colorpicker_rgb_g.png);
118
+ top: 82px;
119
+ left: 212px;
120
+ }
121
+ .colorpicker_rgb_b {
122
+ background-image: url(../images/colorpicker_rgb_b.png);
123
+ top: 112px;
124
+ left: 212px;
125
+ }
126
+ .colorpicker_hsb_h {
127
+ background-image: url(../images/colorpicker_hsb_h.png);
128
+ top: 52px;
129
+ left: 282px;
130
+ }
131
+ .colorpicker_hsb_s {
132
+ background-image: url(../images/colorpicker_hsb_s.png);
133
+ top: 82px;
134
+ left: 282px;
135
+ }
136
+ .colorpicker_hsb_b {
137
+ background-image: url(../images/colorpicker_hsb_b.png);
138
+ top: 112px;
139
+ left: 282px;
140
+ }
141
+ .colorpicker_submit {
142
+ position: absolute;
143
+ width: 22px;
144
+ height: 22px;
145
+ background: url(../images/colorpicker_submit.png) top;
146
+ left: 322px;
147
+ top: 142px;
148
+ overflow: hidden;
149
+ }
150
+ .colorpicker_focus {
151
+ background-position: center;
152
+ }
153
+ .colorpicker_hex.colorpicker_focus {
154
+ background-position: bottom;
155
+ }
156
+ .colorpicker_submit.colorpicker_focus {
157
+ background-position: bottom;
158
+ }
159
+ .colorpicker_slider {
160
+ background-position: bottom;
161
+ }
css/style.css ADDED
@@ -0,0 +1,16 @@
1
+ #colorselector {
2
+ width:36px;
3
+ height:36px;
4
+ background:url(../images/select2.png);
5
+ display:inline-block;
6
+ vertical-align:middle;
7
+ position:relative;
8
+ }
9
+
10
+ #colorselector div {
11
+ width:28px;
12
+ height:28px;
13
+ margin:4px;
14
+ position:absolute;
15
+ background:url(../images/select2.png) 50% 50%;
16
+ }
fonts/Arial.ttf ADDED
Binary file
fonts/Arial_Black.ttf ADDED
Binary file
fonts/Comic_Sans_MS.ttf ADDED
Binary file
fonts/Courier_New.ttf ADDED
Binary file
fonts/Georgia.ttf ADDED
Binary file
fonts/Impact.ttf ADDED
Binary file
fonts/Tahoma.ttf ADDED
Binary file
fonts/Times_New_Roman.ttf ADDED
Binary file
fonts/Trebuchet_MS.ttf ADDED
Binary file
fonts/Verdana.ttf ADDED
Binary file
images/Thumbs.db ADDED
Binary file
images/blank.gif ADDED
Binary file
images/colorpicker_background.png ADDED
Binary file
images/colorpicker_hex.png ADDED
Binary file
images/colorpicker_hsb_b.png ADDED
Binary file
images/colorpicker_hsb_h.png ADDED
Binary file
images/colorpicker_hsb_s.png ADDED
Binary file
images/colorpicker_indic.gif ADDED
Binary file
images/colorpicker_overlay.png ADDED
Binary file
images/colorpicker_rgb_b.png ADDED
Binary file
images/colorpicker_rgb_g.png ADDED
Binary file
images/colorpicker_rgb_r.png ADDED
Binary file
images/colorpicker_select.gif ADDED
Binary file
images/colorpicker_submit.png ADDED
Binary file
images/custom_background.png ADDED
Binary file
images/custom_hex.png ADDED
Binary file
images/custom_hsb_b.png ADDED
Binary file
images/custom_hsb_h.png ADDED
Binary file
images/custom_hsb_s.png ADDED
Binary file
images/custom_indic.gif ADDED
Binary file
images/custom_rgb_b.png ADDED
Binary file
images/custom_rgb_g.png ADDED
Binary file
images/custom_rgb_r.png ADDED
Binary file
images/custom_submit.png ADDED
Binary file
images/select.png ADDED
Binary file
images/select2.png ADDED
Binary file
images/slider.png ADDED
Binary file
index.php CHANGED
@@ -1,17 +1,20 @@
1
<?php
2
/*
3
Plugin Name: Easy Watermark
4
- Description: This plugin allows you to add image watermark to every single image or all images from library at once. It can also be configured to automatically watermark new images as they are uploaded. Watermark can be a png, gif (alpha channel supported in both cases) or jpg image. It's also possibile to set watermark opacity (doesn't apply to png with alpha channel).
5
- Version: 0.1.1
6
Author: Wojtek Szałkiewicz
7
Author URI: http://szalkiewicz.pl/
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
*/
11
require_once dirname(__FILE__) . '/EasyWatermark.php';
12
require_once dirname(__FILE__) . '/EasyWatermarkPlugin.php';
13
require_once dirname(__FILE__) . '/EasyWatermarkSettings.php';
14
15
if(is_admin())
16
// init plugin only in admin panel
17
- EasyWatermarkPlugin::init();
1
<?php
2
/*
3
Plugin Name: Easy Watermark
4
+ Description: This plugin can automatically add image and text watermark to pictures as they are uploaded to wordpress media library. You can also watermark existing images manually (all at once or an every single image). Watermark image can be a png, gif (alpha channel supported in both cases) or jpg. It's also possibile to set watermark opacity (doesn't apply to png with alpha channel). For text watermark you can select font, set color, size, angel and opacity.
5
+ Version: 0.2
6
Author: Wojtek Szałkiewicz
7
Author URI: http://szalkiewicz.pl/
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
*/
11
+ namespace szaleq\Plugins;
12
+
13
+ require_once dirname(__FILE__) . '/plugin.php';
14
require_once dirname(__FILE__) . '/EasyWatermark.php';
15
require_once dirname(__FILE__) . '/EasyWatermarkPlugin.php';
16
require_once dirname(__FILE__) . '/EasyWatermarkSettings.php';
17
18
if(is_admin())
19
// init plugin only in admin panel
20
+ EasyWatermark\Plugin::init();
js/colorpicker.js ADDED
@@ -0,0 +1,484 @@
1
+ /**
2
+ *
3
+ * Color picker
4
+ * Author: Stefan Petre www.eyecon.ro
5
+ *
6
+ * Dual licensed under the MIT and GPL licenses
7
+ *
8
+ */
9
+ (function ($) {
10
+ var ColorPicker = function () {
11
+ var
12
+ ids = {},
13
+ inAction,
14
+ charMin = 65,
15
+ visible,
16
+ tpl = '<div class="colorpicker"><div class="colorpicker_color"><div><div></div></div></div><div class="colorpicker_hue"><div></div></div><div class="colorpicker_new_color"></div><div class="colorpicker_current_color"></div><div class="colorpicker_hex"><input type="text" maxlength="6" size="6" /></div><div class="colorpicker_rgb_r colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_g colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_h colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_s colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_submit"></div></div>',
17
+ defaults = {
18
+ eventName: 'click',
19
+ onShow: function () {},
20
+ onBeforeShow: function(){},
21
+ onHide: function () {},
22
+ onChange: function () {},
23
+ onSubmit: function () {},
24
+ color: 'ff0000',
25
+ livePreview: true,
26
+ flat: false
27
+ },
28
+ fillRGBFields = function (hsb, cal) {
29
+ var rgb = HSBToRGB(hsb);
30
+ $(cal).data('colorpicker').fields
31
+ .eq(1).val(rgb.r).end()
32
+ .eq(2).val(rgb.g).end()
33
+ .eq(3).val(rgb.b).end();
34
+ },
35
+ fillHSBFields = function (hsb, cal) {
36
+ $(cal).data('colorpicker').fields
37
+ .eq(4).val(hsb.h).end()
38
+ .eq(5).val(hsb.s).end()
39
+ .eq(6).val(hsb.b).end();
40
+ },
41
+ fillHexFields = function (hsb, cal) {
42
+ $(cal).data('colorpicker').fields
43
+ .eq(0).val(HSBToHex(hsb)).end();
44
+ },
45
+ setSelector = function (hsb, cal) {
46
+ $(cal).data('colorpicker').selector.css('backgroundColor', '#' + HSBToHex({h: hsb.h, s: 100, b: 100}));
47
+ $(cal).data('colorpicker').selectorIndic.css({
48
+ left: parseInt(150 * hsb.s/100, 10),
49
+ top: parseInt(150 * (100-hsb.b)/100, 10)
50
+ });
51
+ },
52
+ setHue = function (hsb, cal) {
53
+ $(cal).data('colorpicker').hue.css('top', parseInt(150 - 150 * hsb.h/360, 10));
54
+ },
55
+ setCurrentColor = function (hsb, cal) {
56
+ $(cal).data('colorpicker').currentColor.css('backgroundColor', '#' + HSBToHex(hsb));
57
+ },
58
+ setNewColor = function (hsb, cal) {
59
+ $(cal).data('colorpicker').newColor.css('backgroundColor', '#' + HSBToHex(hsb));
60
+ },
61
+ keyDown = function (ev) {
62
+ var pressedKey = ev.charCode || ev.keyCode || -1;
63
+ if ((pressedKey > charMin && pressedKey <= 90) || pressedKey == 32) {
64
+ return false;
65
+ }
66
+ var cal = $(this).parent().parent();
67
+ if (cal.data('colorpicker').livePreview === true) {
68
+ change.apply(this);
69
+ }
70
+ },
71
+ change = function (ev) {
72
+ var cal = $(this).parent().parent(), col;
73
+ if (this.parentNode.className.indexOf('_hex') > 0) {
74
+ cal.data('colorpicker').color = col = HexToHSB(fixHex(this.value));
75
+ } else if (this.parentNode.className.indexOf('_hsb') > 0) {
76
+ cal.data('colorpicker').color = col = fixHSB({
77
+ h: parseInt(cal.data('colorpicker').fields.eq(4).val(), 10),
78
+ s: parseInt(cal.data('colorpicker').fields.eq(5).val(), 10),
79
+ b: parseInt(cal.data('colorpicker').fields.eq(6).val(), 10)
80
+ });
81
+ } else {
82
+ cal.data('colorpicker').color = col = RGBToHSB(fixRGB({
83
+ r: parseInt(cal.data('colorpicker').fields.eq(1).val(), 10),
84
+ g: parseInt(cal.data('colorpicker').fields.eq(2).val(), 10),
85
+ b: parseInt(cal.data('colorpicker').fields.eq(3).val(), 10)
86
+ }));
87
+ }
88
+ if (ev) {
89
+ fillRGBFields(col, cal.get(0));
90
+ fillHexFields(col, cal.get(0));
91
+ fillHSBFields(col, cal.get(0));
92
+ }
93
+ setSelector(col, cal.get(0));
94
+ setHue(col, cal.get(0));
95
+ setNewColor(col, cal.get(0));
96
+ cal.data('colorpicker').onChange.apply(cal, [col, HSBToHex(col), HSBToRGB(col)]);
97
+ },
98
+ blur = function (ev) {
99
+ var cal = $(this).parent().parent();
100
+ cal.data('colorpicker').fields.parent().removeClass('colorpicker_focus');
101
+ },
102
+ focus = function () {
103
+ charMin = this.parentNode.className.indexOf('_hex') > 0 ? 70 : 65;
104
+ $(this).parent().parent().data('colorpicker').fields.parent().removeClass('colorpicker_focus');
105
+ $(this).parent().addClass('colorpicker_focus');
106
+ },
107
+ downIncrement = function (ev) {
108
+ var field = $(this).parent().find('input').focus();
109
+ var current = {
110
+ el: $(this).parent().addClass('colorpicker_slider'),
111
+ max: this.parentNode.className.indexOf('_hsb_h') > 0 ? 360 : (this.parentNode.className.indexOf('_hsb') > 0 ? 100 : 255),
112
+ y: ev.pageY,
113
+ field: field,
114
+ val: parseInt(field.val(), 10),
115
+ preview: $(this).parent().parent().data('colorpicker').livePreview
116
+ };
117
+ $(document).bind('mouseup', current, upIncrement);
118
+ $(document).bind('mousemove', current, moveIncrement);
119
+ },
120
+ moveIncrement = function (ev) {
121
+ ev.data.field.val(Math.max(0, Math.min(ev.data.max, parseInt(ev.data.val + ev.pageY - ev.data.y, 10))));
122
+ if (ev.data.preview) {
123
+ change.apply(ev.data.field.get(0), [true]);
124
+ }
125
+ return false;
126
+ },
127
+ upIncrement = function (ev) {
128
+ change.apply(ev.data.field.get(0), [true]);
129
+ ev.data.el.removeClass('colorpicker_slider').find('input').focus();
130
+ $(document).unbind('mouseup', upIncrement);
131
+ $(document).unbind('mousemove', moveIncrement);
132
+ return false;
133
+ },
134
+ downHue = function (ev) {
135
+ var current = {
136
+ cal: $(this).parent(),
137
+ y: $(this).offset().top
138
+ };
139
+ current.preview = current.cal.data('colorpicker').livePreview;
140
+ $(document).bind('mouseup', current, upHue);
141
+ $(document).bind('mousemove', current, moveHue);
142
+ },
143
+ moveHue = function (ev) {
144
+ change.apply(
145
+ ev.data.cal.data('colorpicker')
146
+ .fields
147
+ .eq(4)
148
+ .val(parseInt(360*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.y))))/150, 10))
149
+ .get(0),
150
+ [ev.data.preview]
151
+ );
152
+ return false;
153
+ },
154
+ upHue = function (ev) {
155
+ fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
156
+ fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
157
+ $(document).unbind('mouseup', upHue);
158
+ $(document).unbind('mousemove', moveHue);
159
+ return false;
160
+ },
161
+ downSelector = function (ev) {
162
+ var current = {
163
+ cal: $(this).parent(),
164
+ pos: $(this).offset()
165
+ };
166
+ current.preview = current.cal.data('colorpicker').livePreview;
167
+ $(document).bind('mouseup', current, upSelector);
168
+ $(document).bind('mousemove', current, moveSelector);
169
+ },
170
+ moveSelector = function (ev) {
171
+ change.apply(
172
+ ev.data.cal.data('colorpicker')
173
+ .fields
174
+ .eq(6)
175
+ .val(parseInt(100*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.pos.top))))/150, 10))
176
+ .end()
177
+ .eq(5)
178
+ .val(parseInt(100*(Math.max(0,Math.min(150,(ev.pageX - ev.data.pos.left))))/150, 10))
179
+ .get(0),
180
+ [ev.data.preview]
181
+ );
182
+ return false;
183
+ },
184
+ upSelector = function (ev) {
185
+ fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
186
+ fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
187
+ $(document).unbind('mouseup', upSelector);
188
+ $(document).unbind('mousemove', moveSelector);
189
+ return false;
190
+ },
191
+ enterSubmit = function (ev) {
192
+ $(this).addClass('colorpicker_focus');
193
+ },
194
+ leaveSubmit = function (ev) {
195
+ $(this).removeClass('colorpicker_focus');
196
+ },
197
+ clickSubmit = function (ev) {
198
+ var cal = $(this).parent();
199
+ var col = cal.data('colorpicker').color;
200
+ cal.data('colorpicker').origColor = col;
201
+ setCurrentColor(col, cal.get(0));
202
+ cal.data('colorpicker').onSubmit(col, HSBToHex(col), HSBToRGB(col), cal.data('colorpicker').el);
203
+ },
204
+ show = function (ev) {
205
+ var cal = $('#' + $(this).data('colorpickerId'));
206
+ cal.data('colorpicker').onBeforeShow.apply(this, [cal.get(0)]);
207
+ var pos = $(this).offset();
208
+ var viewPort = getViewport();
209
+ var top = pos.top + this.offsetHeight;
210
+ var left = pos.left;
211
+ if (top + 176 > viewPort.t + viewPort.h) {
212
+ top -= this.offsetHeight + 176;
213
+ }
214
+ if (left + 356 > viewPort.l + viewPort.w) {
215
+ left -= 356;
216
+ }
217
+ cal.css({left: left + 'px', top: top + 'px'});
218
+ if (cal.data('colorpicker').onShow.apply(this, [cal.get(0)]) != false) {
219
+ cal.show();
220
+ }
221
+ $(document).bind('mousedown', {cal: cal}, hide);
222
+ return false;
223
+ },
224
+ hide = function (ev) {
225
+ if (!isChildOf(ev.data.cal.get(0), ev.target, ev.data.cal.get(0))) {
226
+ if (ev.data.cal.data('colorpicker').onHide.apply(this, [ev.data.cal.get(0)]) != false) {
227
+ ev.data.cal.hide();
228
+ }
229
+ $(document).unbind('mousedown', hide);
230
+ }
231
+ },
232
+ isChildOf = function(parentEl, el, container) {
233
+ if (parentEl == el) {
234
+ return true;
235
+ }
236
+ if (parentEl.contains) {
237
+ return parentEl.contains(el);
238
+ }
239
+ if ( parentEl.compareDocumentPosition ) {
240
+ return !!(parentEl.compareDocumentPosition(el) & 16);
241
+ }
242
+ var prEl = el.parentNode;
243
+ while(prEl && prEl != container) {
244
+ if (prEl == parentEl)
245
+ return true;
246
+ prEl = prEl.parentNode;
247
+ }
248
+ return false;
249
+ },
250
+ getViewport = function () {
251
+ var m = document.compatMode == 'CSS1Compat';
252
+ return {
253
+ l : window.pageXOffset || (m ? document.documentElement.scrollLeft : document.body.scrollLeft),
254
+ t : window.pageYOffset || (m ? document.documentElement.scrollTop : document.body.scrollTop),
255
+ w : window.innerWidth || (m ? document.documentElement.clientWidth : document.body.clientWidth),
256
+ h : window.innerHeight || (m ? document.documentElement.clientHeight : document.body.clientHeight)
257
+ };
258
+ },
259
+ fixHSB = function (hsb) {
260
+ return {
261
+ h: Math.min(360, Math.max(0, hsb.h)),
262
+ s: Math.min(100, Math.max(0, hsb.s)),
263
+ b: Math.min(100, Math.max(0, hsb.b))
264
+ };
265
+ },
266
+ fixRGB = function (rgb) {
267
+ return {
268
+ r: Math.min(255, Math.max(0, rgb.r)),
269
+ g: Math.min(255, Math.max(0, rgb.g)),
270
+ b: Math.min(255, Math.max(0, rgb.b))
271
+ };
272
+ },
273
+ fixHex = function (hex) {
274
+ var len = 6 - hex.length;
275
+ if (len > 0) {
276
+ var o = [];
277
+ for (var i=0; i<len; i++) {
278
+ o.push('0');
279
+ }
280
+ o.push(hex);
281
+ hex = o.join('');
282
+ }
283
+ return hex;
284
+ },
285
+ HexToRGB = function (hex) {
286
+ var hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
287
+ return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
288
+ },
289
+ HexToHSB = function (hex) {
290
+ return RGBToHSB(HexToRGB(hex));
291
+ },
292
+ RGBToHSB = function (rgb) {
293
+ var hsb = {
294
+ h: 0,
295
+ s: 0,
296
+ b: 0
297
+ };
298
+ var min = Math.min(rgb.r, rgb.g, rgb.b);
299
+ var max = Math.max(rgb.r, rgb.g, rgb.b);
300
+ var delta = max - min;
301
+ hsb.b = max;
302
+ if (max != 0) {
303
+
304
+ }
305
+ hsb.s = max != 0 ? 255 * delta / max : 0;
306
+ if (hsb.s != 0) {
307
+ if (rgb.r == max) {
308
+ hsb.h = (rgb.g - rgb.b) / delta;
309
+ } else if (rgb.g == max) {
310
+ hsb.h = 2 + (rgb.b - rgb.r) / delta;
311
+ } else {
312
+ hsb.h = 4 + (rgb.r - rgb.g) / delta;
313
+ }
314
+ } else {
315
+ hsb.h = -1;
316
+ }
317
+ hsb.h *= 60;
318
+ if (hsb.h < 0) {
319
+ hsb.h += 360;
320
+ }
321
+ hsb.s *= 100/255;
322
+ hsb.b *= 100/255;
323
+ return hsb;
324
+ },
325
+ HSBToRGB = function (hsb) {
326
+ var rgb = {};
327
+ var h = Math.round(hsb.h);
328
+ var s = Math.round(hsb.s*255/100);
329
+ var v = Math.round(hsb.b*255/100);
330
+ if(s == 0) {
331
+ rgb.r = rgb.g = rgb.b = v;
332
+ } else {
333
+ var t1 = v;
334
+ var t2 = (255-s)*v/255;
335
+ var t3 = (t1-t2)*(h%60)/60;
336
+ if(h==360) h = 0;
337
+ if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3}
338
+ else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3}
339
+ else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3}
340
+ else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3}
341
+ else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3}
342
+ else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3}
343
+ else {rgb.r=0; rgb.g=0; rgb.b=0}
344
+ }
345
+ return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)};
346
+ },
347
+ RGBToHex = function (rgb) {
348
+ var hex = [
349
+ rgb.r.toString(16),
350
+ rgb.g.toString(16),
351
+ rgb.b.toString(16)
352
+ ];
353
+ $.each(hex, function (nr, val) {
354
+ if (val.length == 1) {
355
+ hex[nr] = '0' + val;
356
+ }
357
+ });
358
+ return hex.join('');
359
+ },
360
+ HSBToHex = function (hsb) {
361
+ return RGBToHex(HSBToRGB(hsb));
362
+ },
363
+ restoreOriginal = function () {
364
+ var cal = $(this).parent();
365
+ var col = cal.data('colorpicker').origColor;
366
+ cal.data('colorpicker').color = col;
367
+ fillRGBFields(col, cal.get(0));
368
+ fillHexFields(col, cal.get(0));
369
+ fillHSBFields(col, cal.get(0));
370
+ setSelector(col, cal.get(0));
371
+ setHue(col, cal.get(0));
372
+ setNewColor(col, cal.get(0));
373
+ };
374
+ return {
375
+ init: function (opt) {
376
+ opt = $.extend({}, defaults, opt||{});
377
+ if (typeof opt.color == 'string') {
378
+ opt.color = HexToHSB(opt.color);
379
+ } else if (opt.color.r != undefined && opt.color.g != undefined && opt.color.b != undefined) {
380
+ opt.color = RGBToHSB(opt.color);
381
+ } else if (opt.color.h != undefined && opt.color.s != undefined && opt.color.b != undefined) {
382
+ opt.color = fixHSB(opt.color);
383
+ } else {
384
+ return this;
385
+ }
386
+ return this.each(function () {
387
+ if (!$(this).data('colorpickerId')) {
388
+ var options = $.extend({}, opt);
389
+ options.origColor = opt.color;
390
+ var id = 'collorpicker_' + parseInt(Math.random() * 1000);
391
+ $(this).data('colorpickerId', id);
392
+ var cal = $(tpl).attr('id', id);
393
+ if (options.flat) {
394
+ cal.appendTo(this).show();
395
+ } else {
396
+ cal.appendTo(document.body);
397
+ }
398
+ options.fields = cal
399
+ .find('input')
400
+ .bind('keyup', keyDown)
401
+ .bind('change', change)
402
+ .bind('blur', blur)
403
+ .bind('focus', focus);
404
+ cal
405
+ .find('span').bind('mousedown', downIncrement).end()
406
+ .find('>div.colorpicker_current_color').bind('click', restoreOriginal);
407
+ options.selector = cal.find('div.colorpicker_color').bind('mousedown', downSelector);
408
+ options.selectorIndic = options.selector.find('div div');
409
+ options.el = this;
410
+ options.hue = cal.find('div.colorpicker_hue div');
411
+ cal.find('div.colorpicker_hue').bind('mousedown', downHue);
412
+ options.newColor = cal.find('div.colorpicker_new_color');
413
+ options.currentColor = cal.find('div.colorpicker_current_color');
414
+ cal.data('colorpicker', options);
415
+ cal.find('div.colorpicker_submit')
416
+ .bind('mouseenter', enterSubmit)
417
+ .bind('mouseleave', leaveSubmit)
418
+ .bind('click', clickSubmit);
419
+ fillRGBFields(options.color, cal.get(0));
420
+ fillHSBFields(options.color, cal.get(0));
421
+ fillHexFields(options.color, cal.get(0));
422
+ setHue(options.color, cal.get(0));
423
+ setSelector(options.color, cal.get(0));
424
+ setCurrentColor(options.color, cal.get(0));
425
+ setNewColor(options.color, cal.get(0));
426
+ if (options.flat) {
427
+ cal.css({
428
+ position: 'relative',
429
+ display: 'block'
430
+ });
431
+ } else {
432
+ $(this).bind(options.eventName, show);
433
+ }
434
+ }
435
+ });
436
+ },
437
+ showPicker: function() {
438
+ return this.each( function () {
439
+ if ($(this).data('colorpickerId')) {
440
+ show.apply(this);
441
+ }
442
+ });
443
+ },
444
+ hidePicker: function() {
445
+ return this.each( function () {
446
+ if ($(this).data('colorpickerId')) {
447
+ $('#' + $(this).data('colorpickerId')).hide();
448
+ }
449
+ });
450
+ },
451
+ setColor: function(col) {
452
+ if (typeof col == 'string') {
453
+ col = HexToHSB(col);
454
+ } else if (col.r != undefined && col.g != undefined && col.b != undefined) {
455
+ col = RGBToHSB(col);
456
+ } else if (col.h != undefined && col.s != undefined && col.b != undefined) {
457
+ col = fixHSB(col);
458
+ } else {
459
+ return this;
460
+ }
461
+ return this.each(function(){
462
+ if ($(this).data('colorpickerId')) {
463
+ var cal = $('#' + $(this).data('colorpickerId'));
464
+ cal.data('colorpicker').color = col;
465
+ cal.data('colorpicker').origColor = col;
466
+ fillRGBFields(col, cal.get(0));
467
+ fillHSBFields(col, cal.get(0));
468
+ fillHexFields(col, cal.get(0));
469
+ setHue(col, cal.get(0));
470
+ setSelector(col, cal.get(0));
471
+ setCurrentColor(col, cal.get(0));
472
+ setNewColor(col, cal.get(0));
473
+ }
474
+ });
475
+ }
476
+ };
477
+ }();
478
+ $.fn.extend({
479
+ ColorPicker: ColorPicker.init,
480
+ ColorPickerHide: ColorPicker.hidePicker,
481
+ ColorPickerShow: ColorPicker.showPicker,
482
+ ColorPickerSetColor: ColorPicker.setColor
483
+ });
484
+ })(jQuery)
js/interface.js CHANGED
@@ -18,4 +18,14 @@
18
$('#easy-watermark-mime').val('');
19
$('#easy-watermark-settings-form').submit();
20
});
21
}(jQuery))
18
$('#easy-watermark-mime').val('');
19
$('#easy-watermark-settings-form').submit();
20
});
21
+
22
+ $('#colorselector').ColorPicker({
23
+ onSubmit: function(hsb, hex, rgb, el){
24
+ $('#easy-watermark-color').val(hex);
25
+ $('#colorselector div').css('backgroundColor', '#' + hex);
26
+ },
27
+ onBeforeShow: function () {
28
+ $(this).ColorPickerSetColor($(this).attr('data-color'));
29
+ }
30
+ });
31
}(jQuery))
languages/easy-watermark-pl_PL.mo CHANGED
Binary file
languages/easy-watermark-pl_PL.po CHANGED
@@ -1,172 +1,232 @@
1
msgid ""
2
msgstr ""
3
- "Project-Id-Version: Easy Watermark 0.1\n"
4
"Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2013-03-21 20:55+0100\n"
6
- "PO-Revision-Date: 2013-03-21 21:03+0100\n"
7
"Last-Translator: Wojtek Szałkiewicz <wojtek@szalkiewicz.pl>\n"
8
- "Language-Team: Wojtek Szałkiewicz <szaleq@gmail.com>\n"
9
- "Language: \n"
10
"MIME-Version: 1.0\n"
11
"Content-Type: text/plain; charset=UTF-8\n"
12
"Content-Transfer-Encoding: 8bit\n"
13
- "X-Poedit-KeywordsList: __;_e\n"
14
- "X-Poedit-Basepath: .\n"
15
- "X-Poedit-Language: polish\n"
16
- "X-Poedit-SearchPath-0: /media/szaleq/Data/easy-watermark/0.1\n"
17
18
- #: /media/szaleq/Data/easy-watermark/0.1/easy-watermark-settings.php:116
19
- msgid "Settings"
20
- msgstr "Ustawienia"
21
-
22
- #: /media/szaleq/Data/easy-watermark/0.1/easy-watermark.php:33
23
msgid "Add watermark"
24
msgstr "Dodaj znak wodny"
25
26
- #: /media/szaleq/Data/easy-watermark/0.1/easy-watermark.php:190
27
msgid "Easy Watermark"
28
msgstr ""
29
30
- #: /media/szaleq/Data/easy-watermark/0.1/easy-watermark.php:197
31
- #: /media/szaleq/Data/easy-watermark/0.1/easy-watermark.php:215
32
msgid "Watermark successfully added."
33
msgstr "Znak wodny został dodany."
34
35
- #: /media/szaleq/Data/easy-watermark/0.1/easy-watermark.php:197
36
- #: /media/szaleq/Data/easy-watermark/0.1/easy-watermark.php:206
37
msgid "Go back"
38
msgstr "Wróć"
39
40
- #: /media/szaleq/Data/easy-watermark/0.1/easy-watermark.php:197
41
- #: /media/szaleq/Data/easy-watermark/0.1/easy-watermark.php:206
42
msgid "go to edit page"
43
msgstr "idź na stronę edycji"
44
45
- #: /media/szaleq/Data/easy-watermark/0.1/easy-watermark.php:215
46
msgid "Go to Media Library"
47
msgstr "Idź do biblioteki mediów"
48
49
- #: /media/szaleq/Data/easy-watermark/0.1/easy-watermark.php:224
50
msgid "Add watermark to all images"
51
msgstr "Dodaj znak wodny do wszystkich obrazów"
52
53
- #: /media/szaleq/Data/easy-watermark/0.1/easy-watermark.php:224
54
msgid "Be carefull with that option. If so