// create a new image from file $vImg = @imagecreatefromgif($temp_file_name); break;*/ case IMAGETYPE_PNG: $file_extension = '.png'; // create a new image from file $vImg = @imagecreatefrompng($temp_file_name); break; default: @unlink($temp_file_name); return; } // create a new true color image $destination_img = @imagecreatetruecolor($img_width, $img_height); // copy and resize part of an image with resampling imagecopyresampled($destination_img, $vImg, 0, 0, (int) $_POST['x1'], (int) $_POST['y1'], $img_width, $img_height, (int) $_POST['w'], (int) $_POST['h']); // define a result image filename $destination_img_file_name = $temp_file_name . $file_extension; // output image to file imagejpeg($destination_img, $destination_img_file_name, $img_quality); @unlink($temp_file_name); return $destination_img_file_name; } } } } } } $cropped_image = upload_image_file(); echo '<img src="' . $cropped_image . '" />';
function update_image($dbc, $image_id, $name, $subject, $description) { $image_file = upload_image_file($image_id); if ('' != $name) { $query = "update images set name = '" . mysql_escape_string($name) . "' where id = '{$image_id}'"; mysqli_query($dbc, $query); } if ('' != $image_file) { $query = "update images set file = '{$image_file}' where id = '{$image_id}'"; mysqli_query($dbc, $query); } if ('' != $subject) { $query = "update images set subject='" . mysql_escape_string($subject) . "' where id = '{$image_id}'"; mysqli_query($dbc, $query); } if ('' != $description) { $query = "update images set description = '" . mysql_escape_string($description) . "' where id = '{$image_id}'"; mysqli_query($dbc, $query); } //$query = "INSERT INTO resource VALUES ('$file_id', '$title', '$file_name', '$creator', '$journal', '$pages', '$year', '$publisher',NULL)"; return true; }