Hjælp til at gemme billede efter crop
Hejsa!Jeg har downloadet dette script: http://da.vidnicholson.com/2006/10/php-image-uploader-and-manipulator.html
Og vil gerne have den færdig croppede fil gemt i en folder. Hvordan gøres dette?
Jeg vil tro at det er denne stump kode der skal bruges:
// handle crop requests:
if(isset($_POST['top']) && isset($_POST['left']) && isset($_POST['width']) && isset($_POST['height']))
{
do { $tempfile = rand(1,10000); } while(file_exists(TEMP_DIR.$tempfile));
$fp = fopen(TEMP_DIR.$tempfile, 'wb');
fwrite($fp, $_SESSION[$unique_session_key]['full']);
fclose($fp);
$sizedata = getimagesize(TEMP_DIR.$tempfile);
$orig_w = $sizedata[0];
$orig_h = $sizedata[1];
$img = imagecreatefromjpeg(TEMP_DIR.$tempfile);
$full_w = intval($_POST['width']);
$full_h = intval($_POST['height']);
$full = imagecreatetruecolor($full_w, $full_h);
imagecopyresized($full, $img, 0, 0, 0, 0, $full_w, $full_h, $orig_w, $orig_h);
$final = imagecreatetruecolor($cropped_width, $cropped_height);
imagecopy($final, $full, 0, 0, -1*(intval($_POST['left'])-100), -1*(intval($_POST['top'])-100), $cropped_width, $cropped_height);
storeImage($final);
unlink(TEMP_DIR.$tempfile);
header("Location: $redirect_after_crop");
}
if(!isset($_SESSION[$unique_session_key]['full']))
{
$_SESSION[$unique_session_key]['full'] = file_get_contents($default_image);
$_SESSION[$unique_session_key]['lowres'] = file_get_contents($default_image);
}
function imgdata($imgid)
{
do{ $filename = TEMP_DIR.rand(1,10000); } while(file_exists($filename));
imagejpeg($imgid, $filename);
$data = file_get_contents($filename);
unlink($filename);
return $data;
}
