function add_image ($id, $image_formats) { $p = $_GET['p']; if(empty($id)) { $id = $_GET['id']; } if ($_FILES['image']['name']) { $image_extension = strtolower(substr($_FILES['image']['name'],strrpos($_FILES['image']['name'],'.')+1)); if($image_extension=='jpg'||$image_extension=='jpeg') { $original_image = "../images/tmp/".$_FILES['image']['name']; move_uploaded_file($_FILES['image']['tmp_name'], $original_image); $vars = getimagesize($original_image); $original_width = $vars[0]; $original_height = $vars[1]; mysql_query("INSERT INTO images (id) VALUES (null)"); $image_id = mysql_insert_id(); $image_name = $p."_".$image_id.".".$image_extension; !empty($image_formats) ? $where = "WHERE name IN ('".str_replace ( ", ", "', '", $image_formats)."')" : $where = ""; $image_formats_sql = mysql_query("SELECT name, width, height FROM images_formats ".$where." ORDER BY id"); while($image_formats = mysql_fetch_array($image_formats_sql)) { if (empty($image_formats['width'])||empty($image_formats['height'])) { $new_width = $original_width; $new_height = $original_height; } else { if ($original_width > $original_height) { $new_width = $image_formats['width']; $new_height = $original_height*($image_formats['width']/$original_width); } if ($original_width < $original_height) { $new_width = $image_formats['width']; $new_height = $original_height*($image_formats['width']/$original_width); } if ($original_width == $original_height) { $new_width = $image_formats['width']; $new_height = $image_formats['width']; } } $new_image = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($new_image, imagecreatefromjpeg($original_image), 0, 0, 0, 0, $new_width, $new_height, $original_width, $original_height); if($image_formats['name']!="max") { $corner_radius = 5; $angle = 0; $corner = imagecreatefrompng('gfx/corner.png'); $corner_width = imagesx($corner); $corner_height = imagesy($corner); $black = ImageColorAllocate($new_image,0,0,0); // Top-left corner $dest_x = 0; $dest_y = 0; imagecolortransparent($corner, $black); imagecopymerge($new_image, $corner, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100); // Bottom-left corner $dest_x = 0; $dest_y = $new_height - $corner_height; $rotated = imagerotate($corner, 90, 0); imagecolortransparent($rotated, $black); imagecopymerge($new_image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100); // Bottom-right corner $dest_x = $new_width - $corner_width; $dest_y = $new_height - $corner_height; $rotated = imagerotate($corner, 180, 0); imagecolortransparent($rotated, $black); imagecopymerge($new_image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100); // Top-right corner $dest_x = $new_width - $corner_width; $dest_y = 0; $rotated = imagerotate($corner, 270, 0); imagecolortransparent($rotated, $black); imagecopymerge($new_image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100); } imagejpeg($new_image, "../images/".$image_formats[0]."/".$image_name); } mysql_query("UPDATE images SET filename = '".$image_name."', type = '".$p."', parent_id = '".$id."' WHERE id = '".$image_id."'"); unlink($original_image); } else { redirect('6'); } } }