Verkleinen van foto
Code (php)
1
Warning: imagejpeg() [function.imagejpeg]: Unable to open 'img.jpg' for writing in /home/remy/domains/404inc.nl/public_html/fotoalbum/test.php on line 20
Daarbij gaat het hier om dit script:
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
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
<?php
function make_jpg($url,$newurl,$maxwidth,$maxheight,$qual) {
list($width, $height) = getimagesize($url);
$ratiow=$width/$maxwidth;
$ratioh=$height/$maxheight;
if ($ratiow > $ratioh) {
$ratio=$ratiow;
} else {
$ratio=$ratioh;
}
$thumb_width=$width/$ratio;
$thumb_height=$height/$ratio;
if ($thumb_height>$height || $thumb_width>$width) {
$thumb_height=$height;
$thumb_width=$width;
}
$img = imagecreatefromjpeg($url);
$thumb = imagecreatetruecolor($thumb_width,$thumb_height);
imagecopyresampled($thumb, $img, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);
imagejpeg($thumb, $newurl,$qual);
imagedestroy($img);
imagedestroy($thumb);
}
$url = "img.jpg";
$newurl = "img.jpg";
make_jpg($url, $newurl, '105', '140', '70');
?>
function make_jpg($url,$newurl,$maxwidth,$maxheight,$qual) {
list($width, $height) = getimagesize($url);
$ratiow=$width/$maxwidth;
$ratioh=$height/$maxheight;
if ($ratiow > $ratioh) {
$ratio=$ratiow;
} else {
$ratio=$ratioh;
}
$thumb_width=$width/$ratio;
$thumb_height=$height/$ratio;
if ($thumb_height>$height || $thumb_width>$width) {
$thumb_height=$height;
$thumb_width=$width;
}
$img = imagecreatefromjpeg($url);
$thumb = imagecreatetruecolor($thumb_width,$thumb_height);
imagecopyresampled($thumb, $img, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);
imagejpeg($thumb, $newurl,$qual);
imagedestroy($img);
imagedestroy($thumb);
}
$url = "img.jpg";
$newurl = "img.jpg";
make_jpg($url, $newurl, '105', '140', '70');
?>
Ook bij een ander script krijg ik dezelfde error:
Code (php)
1
Warning: imagejpeg() [function.imagejpeg]: Unable to open 'imgthumb.jpg' for writing in /home/remy/domains/404inc.nl/public_html/fotoalbum/thumb.php on line 61
Daarbij hoort dit script:
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
74
75
76
77
78
79
80
81
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
<?php
/*
Auteur: ME Wieringa
Email: [email protected]
This function creates a JPG formatted thumb.
sourcePath: Path of original image (this can be a GIF, PNG or JPG)
thumbPath: Path where thumb should be stored (this path should ALWAYS end with .jpg)
thumbWidth: Prefered width of the thumb (0 = relative to its height)
thumbHeight: Prefered height of the thumb (0 = relative to its width)
quality: The quality percentage of the created thumb.
*/
function createThumb($sourcePath, $thumbPath, $thumbWidth = 140, $thumbHeight = 105, $quality = 75)
{
$sourceExtention = strtolower(array_pop(split("[.]", $sourcePath)));
if(strcasecmp($sourceExtention, "gif") === 0)
{
$sourceData = imagecreatefromgif($sourcePath);
}
elseif(strcasecmp($sourceExtention, "png") === 0)
{
$sourceData = imagecreatefrompng($sourcePath);
}
elseif((strcasecmp($sourceExtention, "jpg") === 0) || (strcasecmp($sourceExtention, "jpeg") === 0))
{
$sourceData = imagecreatefromjpeg($sourcePath);
}
else
{
return false;
}
if($sourceData)
{
$sourceWidth = imagesx($sourceData);
$sourceHeight = imagesy($sourceData);
if($thumbWidth > 0)
{
if($thumbHeight === 0)
{
$thumbHeight = round($sourceHeight * ($thumbWidth / $sourceWidth));
}
}
elseif($thumbHeight > 0)
{
$thumbWidth = round($sourceWidth * ($thumbHeight / $sourceHeight));
}
else // No scaling
{
$thumbHeight = $sourceHeight;
$thumbWidth = $sourceWidth;
}
$thumbData = imagecreatetruecolor($thumbWidth, $thumbHeight);
if(imagecopyresampled($thumbData, $sourceData, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $sourceWidth, $sourceHeight))
{
if(imagejpeg($thumbData, $thumbPath, $quality))
{
Imagedestroy($sourceData);
}
else
{
return false;
}
}
else
{
return false;
}
return true;
}
}
createThumb('img.jpg', 'imgthumb.jpg');
?>
/*
Auteur: ME Wieringa
Email: [email protected]
This function creates a JPG formatted thumb.
sourcePath: Path of original image (this can be a GIF, PNG or JPG)
thumbPath: Path where thumb should be stored (this path should ALWAYS end with .jpg)
thumbWidth: Prefered width of the thumb (0 = relative to its height)
thumbHeight: Prefered height of the thumb (0 = relative to its width)
quality: The quality percentage of the created thumb.
*/
function createThumb($sourcePath, $thumbPath, $thumbWidth = 140, $thumbHeight = 105, $quality = 75)
{
$sourceExtention = strtolower(array_pop(split("[.]", $sourcePath)));
if(strcasecmp($sourceExtention, "gif") === 0)
{
$sourceData = imagecreatefromgif($sourcePath);
}
elseif(strcasecmp($sourceExtention, "png") === 0)
{
$sourceData = imagecreatefrompng($sourcePath);
}
elseif((strcasecmp($sourceExtention, "jpg") === 0) || (strcasecmp($sourceExtention, "jpeg") === 0))
{
$sourceData = imagecreatefromjpeg($sourcePath);
}
else
{
return false;
}
if($sourceData)
{
$sourceWidth = imagesx($sourceData);
$sourceHeight = imagesy($sourceData);
if($thumbWidth > 0)
{
if($thumbHeight === 0)
{
$thumbHeight = round($sourceHeight * ($thumbWidth / $sourceWidth));
}
}
elseif($thumbHeight > 0)
{
$thumbWidth = round($sourceWidth * ($thumbHeight / $sourceHeight));
}
else // No scaling
{
$thumbHeight = $sourceHeight;
$thumbWidth = $sourceWidth;
}
$thumbData = imagecreatetruecolor($thumbWidth, $thumbHeight);
if(imagecopyresampled($thumbData, $sourceData, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $sourceWidth, $sourceHeight))
{
if(imagejpeg($thumbData, $thumbPath, $quality))
{
Imagedestroy($sourceData);
}
else
{
return false;
}
}
else
{
return false;
}
return true;
}
}
createThumb('img.jpg', 'imgthumb.jpg');
?>
Op mijn server is gewoon een GD library geinstaleerd en alles is gewoon aanwezig. Iemand die mij kan helpen?
Gewijzigd op 01/01/1970 01:00:00 door Remy Brokke
Na een CHMOD van 755 naar 777 en een <img> tag werkt alles! Toch bedankt voor de mensen die dit topic hebben doorgelezen!