resize image
Jeg har set spm og guides til at resize billeder.Jeg kan bare ikke få dem til at fungere, da mine billeder ikke skal gemmes på serverens disk, men i mysql db.
Jeg har følgende som jeg så tænkte ville fungere
<?php
if($_FILES['fil']['tmp_name'] && $_FILES['fil']['size'] <512000) {
function imageresizejpeg($sourcefile,$maxwidth,$maxheight) {
if($img_src = imagecreatefromstring($sourcefile)) {
$width = imagesx($img_src);
$height = imagesy($img_src);
if($height > $maxheight || $width > $maxwidth) {
$ratio_height=$maxheight/$height;
$ratio_width=$maxwidth/$width;
$ratio=min($ratio_width,$ratio_height);
$newwidth=intval($width*$ratio);
$newheight=intval($height*$ratio);
$img_dst=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
return$img_dst;
imagedestroy($img_src);
imagedestroy($img_dst);
} else {
return false;
}
}
$billede = addslashes(fread(fopen($_FILES['fil']['tmp_name'],"r"),filesize($_FILES['fil']['tmp_name'])));
$billede = imageresizejpeg($billede,'500','500');
mysql_query("INSERT INTO billeder (billede,vareid) VALUES ('$billede','$billede_rel') ") or die(mysql_error());
}
?>
Men der kommer fejl:
Warning: imagecreatefromstring() [function.imagecreatefromstring]: gd-jpeg: JPEG library reports unrecoverable error: in
Warning: imagecreatefromstring() [function.imagecreatefromstring]: Passed data is not in 'JPEG' format in
Warning: imagecreatefromstring() [function.imagecreatefromstring]: Couldn't create GD Image Stream out of Data in