snippet voor foto resize - draai issue
dit werkt perfect.
nu alleen 1 ding
als ik de foto in windows verkenner omdraai (bijv 90°) en dan de foto wil uploaden
laad hij deze op maar niet als de 90° gedraaide foto, wel als de originele versie.
dit is niet echt handig als je fotos hebt getrokken die normaal portret gezien moeten worden
iemand idee
Code (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
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
<?php
/*Toegestane mime-types*/
$msgs_1 = array ();
$errs_1 = array ();
/*
Constanten voor exif_imagetype ()
1 IMAGETYPE_GIF
2 IMAGETYPE_JPEG
3 IMAGETYPE_PNG
*/
$allowed_1 = array (IMAGETYPE_JPEG,IMAGETYPE_PNG,IMAGETYPE_GIF);
function resize_1 ($path_1, $dst_w_1) {
list ($src_w_1, $src_h_1) = getimagesize ($path_1);
if ($dst_w_1 < $src_w_1) {
$ratio_1 = $dst_w_1 / $src_w_1;
$dst_h_1 = ceil ($ratio_1 * $src_h_1);
$src_1 = imagecreatefromjpeg ($path_1);
$dst_1 = imagecreatetruecolor ($dst_w_1, $dst_h_1);
imagecopyresampled ($dst_1, $src_1, 0, 0, 0, 0, $dst_w_1, $dst_h_1, $src_w_1, $src_h_1);
imagejpeg ($dst_1, $path_1, 80);
imagedestroy ($src_1);
imagedestroy ($dst_1);
}
}
// business logic
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$n_1 = count ($_FILES['userfile_1']['error']);
for ($i_1 = 0; $i_1 < $n_1; $i_1++) {
if (!$_FILES['userfile_1']['error'][$i_1]) {
$tmp_1 = $_FILES['userfile_1']['tmp_name'][$i_1];
$name_1 = time().date("m")."1".strrchr($_FILES['userfile_1']['name'][$i_1], ".");
$dir_1 = '../../klantpic/';
if (!in_array (exif_imagetype ($tmp_1), $allowed_1)) {
array_push ($errs_1, 'Sorry, alleen JPG');
}
elseif ($_FILES['userfile_1']['size'][$i_1] > 50000) {
array_push ($errs_1, 'Sorry, foto te groot');
}
else {
$path_1 = $dir_1 . $name_1;
if (is_uploaded_file ($tmp_1)) {
if (move_uploaded_file ($tmp_1, $path_1)) {
resize_1 ($path_1, 1000);
}
}
}
}
}
}?>
/*Toegestane mime-types*/
$msgs_1 = array ();
$errs_1 = array ();
/*
Constanten voor exif_imagetype ()
1 IMAGETYPE_GIF
2 IMAGETYPE_JPEG
3 IMAGETYPE_PNG
*/
$allowed_1 = array (IMAGETYPE_JPEG,IMAGETYPE_PNG,IMAGETYPE_GIF);
function resize_1 ($path_1, $dst_w_1) {
list ($src_w_1, $src_h_1) = getimagesize ($path_1);
if ($dst_w_1 < $src_w_1) {
$ratio_1 = $dst_w_1 / $src_w_1;
$dst_h_1 = ceil ($ratio_1 * $src_h_1);
$src_1 = imagecreatefromjpeg ($path_1);
$dst_1 = imagecreatetruecolor ($dst_w_1, $dst_h_1);
imagecopyresampled ($dst_1, $src_1, 0, 0, 0, 0, $dst_w_1, $dst_h_1, $src_w_1, $src_h_1);
imagejpeg ($dst_1, $path_1, 80);
imagedestroy ($src_1);
imagedestroy ($dst_1);
}
}
// business logic
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$n_1 = count ($_FILES['userfile_1']['error']);
for ($i_1 = 0; $i_1 < $n_1; $i_1++) {
if (!$_FILES['userfile_1']['error'][$i_1]) {
$tmp_1 = $_FILES['userfile_1']['tmp_name'][$i_1];
$name_1 = time().date("m")."1".strrchr($_FILES['userfile_1']['name'][$i_1], ".");
$dir_1 = '../../klantpic/';
if (!in_array (exif_imagetype ($tmp_1), $allowed_1)) {
array_push ($errs_1, 'Sorry, alleen JPG');
}
elseif ($_FILES['userfile_1']['size'][$i_1] > 50000) {
array_push ($errs_1, 'Sorry, foto te groot');
}
else {
$path_1 = $dir_1 . $name_1;
if (is_uploaded_file ($tmp_1)) {
if (move_uploaded_file ($tmp_1, $path_1)) {
resize_1 ($path_1, 1000);
}
}
}
}
}
}?>
lees de comments eens op php.net
Daar zie je staan:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
$image = imagecreatefromstring(file_get_contents($_FILES['image_upload']['tmp_name']));
$exif = exif_read_data($_FILES['image_upload']['tmp_name']);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$image = imagerotate($image,90,0);
break;
case 3:
$image = imagerotate($image,180,0);
break;
case 6:
$image = imagerotate($image,-90,0);
break;
}
}
// $image now contains a resource with the image oriented correctly
?>
$image = imagecreatefromstring(file_get_contents($_FILES['image_upload']['tmp_name']));
$exif = exif_read_data($_FILES['image_upload']['tmp_name']);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$image = imagerotate($image,90,0);
break;
case 3:
$image = imagerotate($image,180,0);
break;
case 6:
$image = imagerotate($image,-90,0);
break;
}
}
// $image now contains a resource with the image oriented correctly
?>
Gewijzigd op 25/01/2016 23:58:48 door Randy vsf
de foto staat nu op de juiste richting in de upload folder
maar de foto zelf op de site is niet mee gedraaid staat nog in originele setting
(dus stond de foto in portret in verkenner en ik draai hem naar landscape -> laad ik deze op->
in de folder op de server staat de foto als landscape maar op de website staat hij nog steeds in portret mode)
Code (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
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
<?php
/*Toegestane mime-types*/
$msgs_1 = array ();
$errs_1 = array ();
/*
Constanten voor exif_imagetype ()
1 IMAGETYPE_GIF
2 IMAGETYPE_JPEG
3 IMAGETYPE_PNG
*/
$allowed_1 = array (IMAGETYPE_JPEG,IMAGETYPE_PNG,IMAGETYPE_GIF);
function resize_1 ($path_1, $dst_w_1) {
list ($src_w_1, $src_h_1) = getimagesize ($path_1);
if ($dst_w_1 < $src_w_1) {
$ratio_1 = $dst_w_1 / $src_w_1;
$dst_h_1 = ceil ($ratio_1 * $src_h_1);
$src_1 = imagecreatefromjpeg ($path_1);
$dst_1 = imagecreatetruecolor ($dst_w_1, $dst_h_1);
imagecopyresampled ($dst_1, $src_1, 0, 0, 0, 0, $dst_w_1, $dst_h_1, $src_w_1, $src_h_1);
imagejpeg ($dst_1, $path_1, 70);
imagedestroy ($src_1);
imagedestroy ($dst_1);
}
}
// business logic
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$n_1 = count ($_FILES['userfile_1']['error']);
for ($i_1 = 0; $i_1 < $n_1; $i_1++) {
if (!$_FILES['userfile_1']['error'][$i_1]) {
$tmp_1 = imagecreatefromstring(file_get_contents($_FILES['userfile_1']['tmp_name'][$i_1]));
$exif = exif_read_data($_FILES['userfile_1']['tmp_name'][$i_1]);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation'])
{
case 8:
$tmp_1 = imagerotate($tmp_1,90,0);
break;
case 3:
$tmp_1 = imagerotate($tmp_1,180,0);
break;
case 6:
$tmp_1 = imagerotate($tmp_1,-90,0);
break;
}
}
$name_1 = time().date("m")."1".strrchr($_FILES['userfile_1']['name'][$i_1], ".");
$dir_1 = '../../../../gallerij/webpic/';
if (!in_array (exif_imagetype ($tmp_1), $allowed_1)) {
array_push ($errs_1, 'Sorry, alleen JPG');
}
elseif ($_FILES['userfile_1']['size'][$i_1] > 50000000) {
array_push ($errs_1, 'Sorry, 50 KB max');
}
else {
$path_1 = $dir_1 . $name_1;
if (is_uploaded_file ($tmp_1)) {
if (move_uploaded_file ($tmp_1, $path_1)) {
resize_1 ($path_1, 1500);
}
}
}
}
}
}?>
/*Toegestane mime-types*/
$msgs_1 = array ();
$errs_1 = array ();
/*
Constanten voor exif_imagetype ()
1 IMAGETYPE_GIF
2 IMAGETYPE_JPEG
3 IMAGETYPE_PNG
*/
$allowed_1 = array (IMAGETYPE_JPEG,IMAGETYPE_PNG,IMAGETYPE_GIF);
function resize_1 ($path_1, $dst_w_1) {
list ($src_w_1, $src_h_1) = getimagesize ($path_1);
if ($dst_w_1 < $src_w_1) {
$ratio_1 = $dst_w_1 / $src_w_1;
$dst_h_1 = ceil ($ratio_1 * $src_h_1);
$src_1 = imagecreatefromjpeg ($path_1);
$dst_1 = imagecreatetruecolor ($dst_w_1, $dst_h_1);
imagecopyresampled ($dst_1, $src_1, 0, 0, 0, 0, $dst_w_1, $dst_h_1, $src_w_1, $src_h_1);
imagejpeg ($dst_1, $path_1, 70);
imagedestroy ($src_1);
imagedestroy ($dst_1);
}
}
// business logic
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$n_1 = count ($_FILES['userfile_1']['error']);
for ($i_1 = 0; $i_1 < $n_1; $i_1++) {
if (!$_FILES['userfile_1']['error'][$i_1]) {
$tmp_1 = imagecreatefromstring(file_get_contents($_FILES['userfile_1']['tmp_name'][$i_1]));
$exif = exif_read_data($_FILES['userfile_1']['tmp_name'][$i_1]);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation'])
{
case 8:
$tmp_1 = imagerotate($tmp_1,90,0);
break;
case 3:
$tmp_1 = imagerotate($tmp_1,180,0);
break;
case 6:
$tmp_1 = imagerotate($tmp_1,-90,0);
break;
}
}
$name_1 = time().date("m")."1".strrchr($_FILES['userfile_1']['name'][$i_1], ".");
$dir_1 = '../../../../gallerij/webpic/';
if (!in_array (exif_imagetype ($tmp_1), $allowed_1)) {
array_push ($errs_1, 'Sorry, alleen JPG');
}
elseif ($_FILES['userfile_1']['size'][$i_1] > 50000000) {
array_push ($errs_1, 'Sorry, 50 KB max');
}
else {
$path_1 = $dir_1 . $name_1;
if (is_uploaded_file ($tmp_1)) {
if (move_uploaded_file ($tmp_1, $path_1)) {
resize_1 ($path_1, 1500);
}
}
}
}
}
}?>
Gewijzigd op 02/02/2016 21:11:47 door chris Bosmans