-
Notifications
You must be signed in to change notification settings - Fork 1
/
tiff-converter.php
129 lines (107 loc) · 2.92 KB
/
tiff-converter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/*
Plugin Name: Tiff Converter
Plugin URI:
Description: Uploaded tiff images will be convertered to JPGs
Version: 1.0
License: GPLv2 or later
Author: humanmade, markoheijnen
Author URI: http://www.hmn.md/
Text Domain: tiffconverter
Domain Path: /languages
*/
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Online: http://www.gnu.org/licenses/gpl.txt
*/
/*
Fix function TODO:
- wp_upload_bits()
NICE HAVE
- Switch when use of Alpha -> Imagick -> $this->image->getimagealphachannel()
*/
if ( ! defined('ABSPATH') )
die();
include dirname( __FILE__ ) . '/inc/converter.php';
if ( defined('WP_CLI') && WP_CLI ) {
include( dirname( __FILE__ ) . '/inc/wp-cli.php' );
}
class Tiff_Converter {
/**
* Load all the code
*
* @since 1.0
*/
public function __construct() {
register_activation_hook( __FILE__, array( $this, 'check_if_usable' ) );
add_filter( 'mime_types', array( $this, 'fix_tif_extension' ) );
new Tiff_Converter_Handle;
}
/**
* Checks on activation if this plugin can be used.
* Will deactivate and die if not possible.
*
* @since 1.0
*/
public function check_if_usable() {
if ( ! $this->is_usable() ) {
deactivate_plugins( __FILE__ );
wp_die(
'<p>' . __( "This plugin requires Imagick/Gmagick to be installed.", 'tiffconverter' ) . '</p>',
'Plugin Activation Error',
array(
'back_link' => true
)
);
}
}
/**
* Checks if the image editor supports tiff images
*
* @since 1.0
*
* @return bool true is possible
*/
public function is_usable() {
return wp_image_editor_supports( array( 'mime_type' => 'image/tiff' ) );
}
/**
* Little hack due the fact that Imagick doesn't reconize TIF as supported
* Uses the filer 'mime_types' to do this fix
*
* @since 1.0
*
* @param array $mime_types
* @return array
*/
public function fix_tif_extension( $mime_types ) {
$mime_types['tiff|tif'] = $mime_types['tif|tiff'];
unset( $mime_types['tif|tiff'] );
return $mime_types;
}
/**
* Request all tiff images in the media library
*
* @since 1.0
*
* @return array Return array with WP_Post objects
*/
public static function get_images() {
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image/tiff'
);
return get_posts( $args );
}
}
$GLOBALS['tiff_converter'] = new Tiff_Converter;