PHP cropping not working, returns black image - Image Cropping System -
basically, im developing image cropping system. , i'm trying resize & convert images jpeg , allow crop functions execute. however, resizes & converts no problem. when add together cropping function, problem returns cropped black image. info posted jquery ajax. , know ajax posting works because debugged it. can provide client side script although don't beleive necessary since problem seems in php.
update: have revised script. problem still persists.
$old_file_path = $user_data['profile_pic']; $new_width = $_post['width_img']; $new_height = $_post['height_img']; $dst_x = 0; $dst_y = 0; $src_x = $_post['left']; $src_y = $_post['top']; $dst_w = $_post['width']; $dst_h = $_post['height']; $src_w = $_post['width']; $src_h = $_post['height']; $file_path = 'core/images/profile/'. substr(md5(time()), 0, 15) . '.' . 'jpg'; $old_file_name = $user_data['profile_pic']; $allowed = array('jpg','jpeg','gif','png'); $file_extension= explode('.', $old_file_name); $file_extn= strtolower(end($file_extension)); $image_p = imagecreatetruecolor($new_width, $new_height); if($file_extn == 'jpg' || $file_extn == 'jpeg'){ $image = imagecreatefromjpeg($old_file_name); }if ($file_extn == 'png'){ $image = imagecreatefrompng($old_file_name); } list($width, $height) = getimagesize($old_file_name); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagejpeg($image_p, $file_path); //begin cropping! $dst_image = imagecreatetruecolor($dst_w,$dst_h); $src_image = imagecreatefromjpeg($old_file_name); imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); imagejpeg($dst_image, $file_path); crop_profile_image($session_user_id, $file_path, $old_file_path); function crop_profile_image($user_id, $file_path, $old_file_path){ if(file_exists($old_file_path) === true){unlink($old_file_path);} mysql_query("update `users` set `profile_pic` = '". mysql_real_escape_string($file_path) ."' `user_id` = " . (int)$user_id); }
use timthumb instead single file , easy use, , has many options. more info can found @ : http://code.google.com/p/timthumb/
thanks.
php
No comments:
Post a Comment