webmail, volgens mij klopt er niets van je if {} else constructies, die zitten een beetje scheef lijkt het wel.
Verder heb ik hier een mooi stukje code voor thumbnails, ook met zwarte balken etc om de plaatjes toch mooi vierkant te houden (aangezien dat altijd 1 van mijn grootste ergenissen was)
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
| function _image_info($src)
{
list($source->width, $source->height, $source->type_num, $source->attr) = getimagesize($src);
switch($source->type_num)
{
case 1: $source->type = "gif"; break;
case 2: $source->type = "jpg"; break;
case 3: $source->type = "png"; break;
case 4: $source->type = "swf"; break;
case 5: $source->type = "psd"; break;
case 6: $source->type = "bmp"; break;
case 7: $source->type = "tiff"; break;
case 8: $source->type = "tiff"; break;
case 9: $source->type = "jpc"; break;
case 10: $source->type = "jp2"; break;
case 11: $source->type = "jpx"; break;
case 12: $source->type = "jb2"; break;
case 13: $source->type = "swc"; break;
case 14: $source->type = "iff"; break;
case 15: $source->type = "wmbp"; break;
case 16: $source->type = "xbm"; break;
default: $source->type = "unknown"; break;
}
return $source;
}
# **********************************************************************************************************************
# _image_resize();
# This function will resize an image (JPG or PNG) , with the following parameters.
#
# src source file, for input
# dst destination file, for output
# max_height the maximum height value
# max_width the maximum width value
# quality percentage of compression going to be used (default : 100%)
# enlarge when true AND when an image is smaller than max_height & max_width : the image will be
# scaled larger, default value = false, because this will cause weird pixel effects in most cases.
# square when true : image will be a square , but with black borders where needed to keep proportions
# *********************************************************************************************************************
function _image_resize($src, $dst, $max_height, $max_width, $quality = 100, $enlarge = false, $square = true)
{
$picBG = "0,0,0";
$picFG = "104,104,104";
$font = 1;
$source = _image_info($src);
$source->file = $src;
$dest->file = $dst;
$dest->header = "Content-type: image/".$source->type;
if ($source->width >= $source->height)
{
$ratio = $source->width / $max_width;
$dest->height = floor($source->height / $ratio);
$dest->width = $max_width;
}
else
{
$ratio = $source->height / $max_height;
$dest->width = floor($source->width / $ratio);
$dest->height = $max_height;
}
if ($enlarge == false)
{
if (($dest->height > $source->height) OR ($dest->width > $source->height))
{
$dest->width = $source->width;
$dest->height = $source->height;
}
}
// header($dest->header);
switch($source->type_num) {
case 2:
$source->image = imageCreateFromJPEG($source->file);
break;
case 3:
$source->image = imageCreateFromPNG($source->file);
break;
}
if ($square == true)
{
if ($dest->width > $dest->height)
{
$dest->image = imagecreatetruecolor($dest->width, $dest->width);
$posX = 0;
$posY = ($dest->width - $dest->height) / 2;
}
else
{
$dest->image = imagecreatetruecolor($dest->height, $dest->height);
$posY = 0;
$posX = ($dest->height - $dest->width) / 2;
}
}
else
{
$dest->image = imagecreatetruecolor($dest->width, $dest->height);
$posX = 0;
$posY = 0;
}
@imagecopyresampled($dest->image, $source->image, $posX, $posY, 0, 0, $dest->width, $dest->height, $source->width, $source->height);
switch($source->type_num)
{
case 2: @imageJPEG($dest->image, $dest->file, $quality); break;
case 3: @imagePNG($dest->image, $dest->file); break;
}
} |
Ook zou ik je aanraden, de plaatjes niet in de database te zetten, aangezien dit erg veel performance kost om die er weer uit te halen, je zou ze beter op het filesystem kunnen opslaan (evt met rare ge-md5-de namen oid).
[
Voor 9% gewijzigd door
sorted.bits op 12-03-2004 07:36
]