forked from MagicMirrorOrg/MagicMirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doimage.php
executable file
·96 lines (71 loc) · 2.79 KB
/
doimage.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
<?php
//error_reporting(E_ALL);ini_set('display_errors', 1);
function autoRotateImage($image) {
$orientation = $image->getImageOrientation();
switch($orientation) {
case imagick::ORIENTATION_BOTTOMRIGHT:
$image->rotateimage("#000", 180); // rotate 180 degrees
break;
case imagick::ORIENTATION_RIGHTTOP:
$image->rotateimage("#000", 90); // rotate 90 degrees CW
break;
case imagick::ORIENTATION_LEFTBOTTOM:
$image->rotateimage("#000", -90); // rotate 90 degrees CCW
break;
}
// Now that it's auto-rotated, make sure the EXIF data is correct in case the EXIF gets saved with the image!
$image->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
}
if (isset($_POST['myFile']) && !empty($_POST['myFile']))
{
// Example:
$path_parts = pathinfo($_POST['myFile']);
//echo $path_parts['dirname'], "\n";
//echo $path_parts['basename'], "\n";
//echo $path_parts['extension'], "\n";
$tmp_filename = "uploads/" . $_POST['myFile']; // If it doesn't work change this to 'name'
$im = new Imagick($tmp_filename);
// Rotate correctly (using EXIF data)
autoRotateImage($im);
// Change format to jpg
//$im->setImageFormat( "jpg" );
$im->setImageColorspace(255); // TODO might not be needed?
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality(90); // TODO set accordingly (in conjunction with blur setting)
$im->setImageFormat('jpeg');
// TODO proper size, and blur setting. Also try FILTER_CATROM (similar to LANCZOS but much faster)
// TODO disable upscaling
$im->resizeImage(1080,1920,Imagick::FILTER_CATROM,1, true);
// overwrite tmp file
$im->writeImage($tmp_filename); // TODO if this doesn't work, can we just send output to $destfilename below?
$im->clear();
$im->destroy();
// Set up dest filename (image_timestamp.jpg)
$thumb_filename = $path_parts['filename'] . "_thumb.jpg";
$thumb_destfilename = "uploads/" . $thumb_filename;
// Create thumb
$thumb = new Imagick($tmp_filename);
// TODO proper size, and blur setting. Also try FILTER_CATROM (similar to LANCZOS but much faster)
// TODO disable upscaling
$thumb->resizeImage(640,480,Imagick::FILTER_CATROM,1, true);
$thumb->writeImage($thumb_destfilename);
$thumb->clear(); // TODO remove?
$thumb->destroy();
echo 'success ' . $thumb_filename . ' ' . $tmp_filename; // Send thumb filename to server script
/*
Reference...
$im = new imagick( 'test.pdf[ 0]' );
// convert to jpg
$im->setImageColorspace(255);
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality(60);
$im->setImageFormat('jpeg');
//resize
$im->resizeImage(290, 375, imagick::FILTER_LANCZOS, 1);
//write image on server
$im->writeImage('thumb.jpg');
$im->clear();
$im->destroy();
*/
}
?>