Ik ben al een tijdje bezig om het volgende aan de praat te krijgen.
Ik heb op mijn server: www.overdatum.nl/testt/create_thumb.php
een thumbnail creater staan, die van een orginele foto een kleinere versie kan maken.
Dat werkt goed, er wordt een thumbnail gemaakt in de juiste map.
Nu gebruik ik het volgende om mijn thumbnail te laten zien:
wat niet werkt...
Nu heb ik ook al de variant print ipv echo geprobeerd, maar ook dat lost niks op.
Ga ik dan handmatig naar het adres, dan krijg ik de foto gewon wel op mijn scherm gereduceerd tot een thumbnailtje.
wat doe ik hier fout?
Ik heb op mijn server: www.overdatum.nl/testt/create_thumb.php
een thumbnail creater staan, die van een orginele foto een kleinere versie kan maken.
code:
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
| <?php
if (array_key_exists('create', $_POST)) {
// define constants
define('SOURCE_DIR', '/storage/mijndomein/users/108498/public/sites/www.overdatum.nl/testt/images/upload/');
define('THUMBS_DIR', '/storage/mijndomein/users/108498/public/sites/www.overdatum.nl/testt/thumbs/');
define('MAX_WIDTH', 120);
define('MAX_HEIGHT', 90);
}
// get image name and build full pathname
if (!empty($_POST['pix'])) {
$original = SOURCE_DIR.$_POST['pix'];
$result = 'No image selected';
}
else {
$original = NULL;
}
// abandon processing if no image selected
if (!$original) {
$result = 'No image selected';
}
// otherwise resize the image
else {
// begin by getting the details of the original
list($width, $height, $type) = getimagesize($original);
// calculate the scaling ratio
if ($width <= MAX_WIDTH && $height <= MAX_HEIGHT) {
$ratio = 1;
}
elseif ($width > $height) {
$ratio = MAX_WIDTH/$width;
}
else {
$ratio = MAX_HEIGHT/$height;
}
// strip the extension off the image filename
$imagetypes = array('/\.gif$/','/\.jpg$/','/\.jpeg$/','/\.png$/');
$name = preg_replace($imagetypes, '', basename($original));
// create an image resource for the original
switch($type) {
case 1:
$source = @ imagecreatefromgif($original);
if (!$source) {
$result = 'Cannot process GIF files. Please use JPEG or PNG.';
}
break;
case 2:
$source = imagecreatefromjpeg($original);
break;
case 3:
$source = imagecreatefrompng($original);
break;
default:
$source = NULL;
$result = 'Cannot identify file type.';
}
// make sure the image resource is OK
if (!$source) {
$result = 'Problem copying original';
}
else {
// calculate the dimensions of the thumbnail
$thumb_width = round($width * $ratio);
$thumb_height = round($height * $ratio);
// create an image resource for the thumbnail
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
// create the resized copy
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumb_width,
$thumb_height, $width, $height);
// save the resized copy
switch($type) {
case 1:
if (function_exists('imagegif')) {
$success = imagegif($thumb, THUMBS_DIR.$name.'_od.gif');
$thumb_name = $name.'_od.gif';
}
else {
$success = imagejpeg($thumb, THUMBS_DIR.$name.'_od.jpg', 50);
$thumb_name = $name.'_od.jpg';
}
break;
case 2:
$success = imagejpeg($thumb, THUMBS_DIR.$name.'_od.jpg', 100);
$thumb_name = $name.'_od.jpg';
break;
case 3:
$success = imagepng($thumb, THUMBS_DIR.$name.'_od.png');
$thumb_name = $name.'_od.png';
}
if ($success) {
$result = "$thumb_name";
}
else {
$result = 'Problem creating thumbnail';
}
// remove the image resources from memory
imagedestroy($source);
imagedestroy($thumb);
}
}
?> |
Dat werkt goed, er wordt een thumbnail gemaakt in de juiste map.
Nu gebruik ik het volgende om mijn thumbnail te laten zien:
code:
1
2
3
4
5
6
7
| <?php
if (isset($result)) {
echo '<img scr="www.overdatum.nl/testt/thumbs/';
echo $thumb_name;
echo '" />"';
}
?> |
wat niet werkt...
Nu heb ik ook al de variant print ipv echo geprobeerd, maar ook dat lost niks op.
Ga ik dan handmatig naar het adres, dan krijg ik de foto gewon wel op mijn scherm gereduceerd tot een thumbnailtje.
wat doe ik hier fout?
[ Voor 68% gewijzigd door Zakkenwasser op 09-10-2008 08:25 ]
PSP 1000 @ 6.60 Pro C2 [+256GB]
PSVita @ Henkaku Enso [+256GB]
3DS @ Luma (B9S) [+160GB]
Nintendo Switch 3.0.1 [+256GB]