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
|
<?php
/**
* Tidypics Thumbnail Creation Test
*
* Called through ajax, but registered as an Elgg action.
*
*/
elgg_load_library('tidypics:resize');
$guid = get_input('guid');
$image = get_entity($guid);
if (!$image || !($image instanceof TidypicsImage)) {
register_error(elgg_echo('tidypics:thumbnail_tool:unknown_image'));
forward(REFERER);
}
$filename = $image->getFilename();
$container_guid = $image->container_guid;
if (!$filename || !$container_guid) {
register_error(elgg_echo('tidypics:thumbnail_tool:invalid_image_info'));
forward(REFERER);
}
$title = $image->title;
$prefix = "image/$container_guid/";
$filestorename = substr($filename, strlen($prefix));
$image_lib = elgg_get_plugin_setting('image_lib', 'tidypics');
if (!$image_lib) {
$image_lib = "GD";
}
// ImageMagick command line
if ($image_lib == 'ImageMagick') {
if (!tp_create_im_cmdline_thumbnails($image, $prefix, $filestorename)) {
trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick command line', E_USER_WARNING);
register_error(elgg_echo('tidypics:thumbnail_tool:create_failed'));
forward(REFERER);
}
// imagick PHP extension
} else if ($image_lib == 'ImageMagickPHP') {
if (!tp_create_imagick_thumbnails($image, $prefix, $filestorename)) {
trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick PHP', E_USER_WARNING);
register_error(elgg_echo('tidypics:thumbnail_tool:create_failed'));
forward(REFERER);
}
// gd
} else {
if (!tp_create_gd_thumbnails($image, $prefix, $filestorename)) {
trigger_error('Tidypics warning: failed to create thumbnails - GD', E_USER_WARNING);
register_error(elgg_echo('tidypics:thumbnail_tool:create_failed'));
forward(REFERER);
}
}
$url = elgg_normalize_url("photos/thumbnail/$guid/large");
system_message(elgg_echo('tidypics:thumbnail_tool:created'));
if (elgg_is_xhr()) {
echo json_encode(array(
'guid' => $guid,
'title' => $title,
'thumbnail_src' => $url
));
}
forward(REFERER);
|