Hallo,
Ik ben een thumbnail script aan het maken, en ben gekomen tot het volgende:
Alles gaat goed, de files worden gemaakt, en komen op de site te staan, alleen zijn ze helemaal zwart. Het script zorgt ervoor dat de thumbnail 128x76 wordt en het zwarte vlak is ook die grootte. Alleen de kleuren zijn dus verdwenen. Weet iemand hoe dit kan? Alvast bedankt!
Ik ben een thumbnail script aan het maken, en ben gekomen tot het volgende:
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
| $img_name = "$path"."$file"; $new_name = "$path"."$filename"."_t.jpg"; $handle = @imagecreatefromjpeg("$path"."$file"); $srcWidth = @imagesx($handle); $srcHeight = @imagesy($handle); $newHandle = @imagecreatetruecolor(128, 76); if($srcHeight < $srcWidth) { $ratio = (double)($srcHeight / $dstHeight); $cpyWidth = round(128 * $ratio); if ($cpyWidth > $srcWidth) { $ratio = (double)($srcWidth / 128); $cpyWidth = $srcWidth; $cpyHeight = round(76 * $ratio); $xOffset = 0; $yOffset = round(($srcHeight - $cpyHeight) / 2); } else { $cpyHeight = $srcHeight; $xOffset = round(($srcWidth - $cpyWidth) / 2); $yOffset = 0; } } else { $ratio = (double)($srcWidth / 128); $cpyHeight = round(76 * $ratio); if ($cpyHeight > $srcHeight) { $ratio = (double)($srcHeight / 76); $cpyHeight = $srcHeight; $cpyWidth = round(128 * $ratio); $xOffset = round(($srcWidth - $cpyWidth) / 2); $yOffset = 0; } else { $cpyWidth = $srcWidth; $xOffset = 0; $yOffset = round(($srcHeight - $cpyHeight) / 2); } } !@imagecopyresampled($newHandle, $handle, 0, 0, $xOffset, $yOffset, 128, 76, $cpyWidth, $cpyHeight); imagedestroy($handle); @imagejpeg($newHandle, "$path"."$filename"."_t.jpg", 90); @imagedestroy($newHandle); |
Alles gaat goed, de files worden gemaakt, en komen op de site te staan, alleen zijn ze helemaal zwart. Het script zorgt ervoor dat de thumbnail 128x76 wordt en het zwarte vlak is ook die grootte. Alleen de kleuren zijn dus verdwenen. Weet iemand hoe dit kan? Alvast bedankt!
[ Voor 10% gewijzigd door Verwijderd op 19-01-2006 20:08 . Reden: Even de code wat leesbaarder maken ]