PHP Image resize returns only black background.
I read all similar posts here, but none of them fixed my problem.
Here is the code:
$namef = $_FILES['image']['name'];
$tmp_name = $_FILES['image']['tmp_name'];
$src = imagecreatefromjpeg($tmp_name);
$location = "../userpictures/standard/".$mdid.".".$mzad;
move_uploaded_file($tmp_name, $location);
list($width, $height, $type, $att) = getimagesize($location);
$newwidth = 200;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,
$width,$height);
$locations = "../userpictures/medium/".$mdid.".".$mzad;
imagejpeg($tmp,$locations,100);
move_uploaded_file($tmp_name, $location);
I’ve checked whether this code was valid on php tutorials and it was ok with the code.
You create your images with imagecreatetruecolor, which create a new image of W x H filled in black.
See http://php.net/manual/en/function.imagecreatetruecolor.php: