probleem met resizen image
als ik een gebruiker aan maak kan ik hierbij een profiel foto uploaden.
deze moet in de map /uploaded/avatar_realsize/ terechtkomen.
op het moment dat de foto daar staat moet deze ook in 3 maten in de map /uploaded/avatar/ komen
deze maten zijn 50x50, 100x100 en 250x250
het probleem dat ik heb is dat de class die ik daarvoor moet gebruiken mij een paar warnings terug geeft de ik niet begrijp:
de warnings:
Warning: getimagesize(D:\Program Files\devel\xampp\htdocs\git\Business-leaders/upload/avatar_realsize/test/avatar_realsize/49png): failed to open stream: No such file or directory in D:\Program Files\devel\xampp\htdocs\git\Business-leaders\includes\class_image.php on line 14
Warning: Division by zero in D:\Program Files\devel\xampp\htdocs\git\Business-leaders\includes\class_image.php on line 26
Warning: Division by zero in D:\Program Files\devel\xampp\htdocs\git\Business-leaders\includes\class_image.php on line 27
Warning: imagecreatetruecolor(): Invalid image dimensions in D:\Program Files\devel\xampp\htdocs\git\Business-leaders\includes\class_image.php on line 31
Warning: imagecreatefrompng(D:\Program Files\devel\xampp\htdocs\git\Business-leaders/upload/avatar_realsize/test/avatar_realsize/49png): failed to open stream: No such file or directory in D:\Program Files\devel\xampp\htdocs\git\Business-leaders\includes\class_image.php on line 39
Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in D:\Program Files\devel\xampp\htdocs\git\Business-leaders\includes\class_image.php on line 46
Warning: imagepng() expects parameter 1 to be resource, boolean given in D:\Program Files\devel\xampp\htdocs\git\Business-leaders\admin\gebruikers\uploadpicture.php on line 56
hieronder de code :
uploadpicture.php
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
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
<?php
function __autoload($class_name)
{
include_once('./../../includes/class_'. strtolower($class_name) . '.php');
}
if(isset($_FILES['profielFoto']))
{
$path = Settings::$include_path."/uploaded/avatar_realsize/test/avatar_realsize/";
$valid_formats = array("jpg", "png","jpeg");
$name = $_FILES['profielFoto']['name'];
$size = $_FILES['profielFoto']['size'];
// placeholder naamgeving
$name_image ="49";
// succes met het uploaden maakt dit true
$succesfullUpload = "false";
if(strlen($name)!= 0)
{
list($txt, $ext) = explode(".", $name);
if(in_array($ext,$valid_formats))
{
if($size>(10*10))
{
$actual_image_name = $name_image;
$tmp = $_FILES['profielFoto']['tmp_name'];
if(move_uploaded_file($tmp, $path.$actual_image_name.".".$ext))
{
// placeholder moet terug naar pagina.
echo Settings::$include_path."/uploaded/".$path."". $actual_image_name.".".$ext;
$succesfullUpload = "true";
}
else
echo "Mislukt!";
}
else
echo "Minimale afbeeldings grootte is 250 pixel bij 250 pixel.";
}
else
echo "Verkeerde upload format.";
}
else
echo "Selecteer een afbeelding.";
}
if($succesfullUpload === "true")
{
list($txt, $ext) = explode(".", $name);
$include_path=Settings::$include_path."/upload/avatar_realsize/test/avatar_realsize/".$name_image.$ext;
// 50x50
$small=image::resizeImage($include_path,$ext,50,50);
if($ext == "png")
{
$imageResized = imagepng($small,Settings::$include_path."/uploaded/avatar_realsize/test/avatar/".$name_image."_small.".$ext."");
}
elseif($ext== "jpg" || $ext == "jpeg")
{
$imageResizedimagejpeg($small,Settings::$include_path."/uploaded/avatar_realsize/test/avatar/".$name_image."_small.".$ext."");
}
else
{
echo "extentie is niet toegestaan";
}
}
?>
function __autoload($class_name)
{
include_once('./../../includes/class_'. strtolower($class_name) . '.php');
}
if(isset($_FILES['profielFoto']))
{
$path = Settings::$include_path."/uploaded/avatar_realsize/test/avatar_realsize/";
$valid_formats = array("jpg", "png","jpeg");
$name = $_FILES['profielFoto']['name'];
$size = $_FILES['profielFoto']['size'];
// placeholder naamgeving
$name_image ="49";
// succes met het uploaden maakt dit true
$succesfullUpload = "false";
if(strlen($name)!= 0)
{
list($txt, $ext) = explode(".", $name);
if(in_array($ext,$valid_formats))
{
if($size>(10*10))
{
$actual_image_name = $name_image;
$tmp = $_FILES['profielFoto']['tmp_name'];
if(move_uploaded_file($tmp, $path.$actual_image_name.".".$ext))
{
// placeholder moet terug naar pagina.
echo Settings::$include_path."/uploaded/".$path."". $actual_image_name.".".$ext;
$succesfullUpload = "true";
}
else
echo "Mislukt!";
}
else
echo "Minimale afbeeldings grootte is 250 pixel bij 250 pixel.";
}
else
echo "Verkeerde upload format.";
}
else
echo "Selecteer een afbeelding.";
}
if($succesfullUpload === "true")
{
list($txt, $ext) = explode(".", $name);
$include_path=Settings::$include_path."/upload/avatar_realsize/test/avatar_realsize/".$name_image.$ext;
// 50x50
$small=image::resizeImage($include_path,$ext,50,50);
if($ext == "png")
{
$imageResized = imagepng($small,Settings::$include_path."/uploaded/avatar_realsize/test/avatar/".$name_image."_small.".$ext."");
}
elseif($ext== "jpg" || $ext == "jpeg")
{
$imageResizedimagejpeg($small,Settings::$include_path."/uploaded/avatar_realsize/test/avatar/".$name_image."_small.".$ext."");
}
else
{
echo "extentie is niet toegestaan";
}
}
?>
class_image.php
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
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
<?PHP
class image
{
static private $originalImage;
static private $type;
static private $toWidth;
static private $toHeight;
//functie resized een image, parameters: source naar image, type image, breedte, hoogte
//geeft een geresizede image terug
public static function resizeImage($originalImage,$type,$toWidth,$toHeight)
{
// Get the original geometry and calculate scales
list($width, $height) = getimagesize($originalImage);
$xscale = $width/$toWidth;
$yscale = $height/$toHeight;
// Recalculate new size with default ratio
if($yscale>$xscale)
{
$new_width = round($width * (1 / $yscale));
$new_height = round($height * (1 / $yscale));
}
else
{
$new_width = round($width * (1 / $xscale));
$new_height = round($height * (1 / $xscale));
}
// Resize the original image
$imageResized = imagecreatetruecolor($new_width, $new_height);
if($type == 'jpg' || $type == 'jpeg')
{
$imageTmp = imagecreatefromjpeg($originalImage);
}
else if($type == 'png')
{
$imageTmp = imagecreatefrompng($originalImage);
}
else if($type == 'gif')
{
$imageTmp = imagecreatefromgif($originalImage);
}
imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
return $imageResized;
}
}
?>
class image
{
static private $originalImage;
static private $type;
static private $toWidth;
static private $toHeight;
//functie resized een image, parameters: source naar image, type image, breedte, hoogte
//geeft een geresizede image terug
public static function resizeImage($originalImage,$type,$toWidth,$toHeight)
{
// Get the original geometry and calculate scales
list($width, $height) = getimagesize($originalImage);
$xscale = $width/$toWidth;
$yscale = $height/$toHeight;
// Recalculate new size with default ratio
if($yscale>$xscale)
{
$new_width = round($width * (1 / $yscale));
$new_height = round($height * (1 / $yscale));
}
else
{
$new_width = round($width * (1 / $xscale));
$new_height = round($height * (1 / $xscale));
}
// Resize the original image
$imageResized = imagecreatetruecolor($new_width, $new_height);
if($type == 'jpg' || $type == 'jpeg')
{
$imageTmp = imagecreatefromjpeg($originalImage);
}
else if($type == 'png')
{
$imageTmp = imagecreatefrompng($originalImage);
}
else if($type == 'gif')
{
$imageTmp = imagecreatefromgif($originalImage);
}
imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
return $imageResized;
}
}
?>
Quote:
Warning: getimagesize(D:\Program Files\devel\xampp\htdocs\git\Business-leaders/upload/avatar_realsize/test/avatar_realsize/49png): failed to open stream: No such file or directory in D:\Program Files\devel\xampp\htdocs\git\Business-leaders\includes\class_image.php on line 14
failed to open stream, betekent in dit geval met de aan zekerheid grenzende waarschijnlijkheid dat de bestandsnaam fout is.
En dat veroorzaakt al die andere warnings.
Toevoeging op 29/05/2013 10:45:16:
dat heeft het probleem niet opgelost