model = $model; } //////////////////////////////////////////////////////////////////////////////////////// // Public Methods // //////////////////////////////////////////////////////////////////////////////////////// public function display() { global $WD_BWG_UPLOAD_DIR; $popup_width = ((int) (isset($_GET['width']) ? esc_html($_GET['width']) : '800')) - 30; $image_width = $popup_width - 40; $popup_height = ((int) (isset($_GET['height']) ? esc_html($_GET['height']) : '500')) - 50; $image_height = $popup_height - 40; $instagram_post_width = ((int) (isset($_GET['instagram_post_width']) ? esc_html($_GET['instagram_post_width']) : $image_width)); $instagram_post_height = ((int) (isset($_GET['instagram_post_height']) ? esc_html($_GET['instagram_post_height']) : $image_height)); if ($instagram_post_width) { if ($image_height / ($instagram_post_height + 96) < $image_width / $instagram_post_width) { $instagram_post_width = ($image_height - 96) * $instagram_post_width / $instagram_post_height + 16; $instagram_post_height = $image_height; } else { $instagram_post_height = ($image_width - 16) * $instagram_post_height / $instagram_post_width + 16; $instagram_post_width = $image_width; } } $image_id = (isset($_GET['image_id']) ? esc_html($_GET['image_id']) : '0'); ?>
model->get_option_data(); $thumb_width = $options->upload_thumb_width; $thumb_height = $options->upload_thumb_height; $popup_width = ((int) (isset($_GET['width']) ? esc_html($_GET['width']) : '800')) - 50; $image_width = $popup_width - $thumb_width - 70; $popup_height = ((int) (isset($_GET['height']) ? esc_html($_GET['height']) : '500')) - 75; $image_height = $popup_height - 70; $image_id = (isset($_GET['image_id']) ? esc_html($_GET['image_id']) : '0'); $edit_type = (isset($_POST['edit_type']) ? esc_html($_POST['edit_type']) : ''); $x = (isset($_POST['x']) ? (int) $_POST['x'] : 0); $y = (isset($_POST['y']) ? (int) $_POST['y'] : 0); $w = (isset($_POST['w']) ? (int) $_POST['w'] : 0); $h = (isset($_POST['h']) ? (int) $_POST['h'] : 0); if (isset($_GET['image_url'])) { $image_data = new stdClass(); $image_data->image_url = (isset($_GET['image_url']) ? esc_html(stripcslashes($_GET['image_url'])) : ''); $image_data->thumb_url = (isset($_GET['thumb_url']) ? esc_html(stripcslashes($_GET['thumb_url'])) : ''); $filename = htmlspecialchars_decode(ABSPATH . $WD_BWG_UPLOAD_DIR . $image_data->image_url, ENT_COMPAT | ENT_QUOTES); $thumb_filename = htmlspecialchars_decode(ABSPATH . $WD_BWG_UPLOAD_DIR . $image_data->thumb_url, ENT_COMPAT | ENT_QUOTES); $form_action = add_query_arg(array('action' => 'editThumb', 'type' => 'crop', 'image_id' => $image_id, 'image_url' => $image_data->image_url, 'thumb_url' => $image_data->thumb_url, 'width' => '800', 'height' => '500', 'TB_iframe' => '1'), admin_url('admin-ajax.php')); } else { $image_data = $this->model->get_image_data($image_id); $image_data->image_url = stripslashes($image_data->image_url); $filename = htmlspecialchars_decode(ABSPATH . $WD_BWG_UPLOAD_DIR . $image_data->image_url, ENT_COMPAT | ENT_QUOTES); $thumb_filename = htmlspecialchars_decode(ABSPATH . $WD_BWG_UPLOAD_DIR . $image_data->thumb_url, ENT_COMPAT | ENT_QUOTES); $form_action = add_query_arg(array('action' => 'editThumb', 'type' => 'crop', 'image_id' => $image_id, 'width' => '800', 'height' => '500', 'TB_iframe' => '1'), admin_url('admin-ajax.php')); } @ini_set('memory_limit', '-1'); list($width_orig, $height_orig, $type_orig) = getimagesize($filename); if ($edit_type == 'crop') { if ($type_orig == 2) { $img_r = imagecreatefromjpeg($filename); $dst_r = ImageCreateTrueColor($thumb_width, $thumb_height); imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $thumb_width, $thumb_height, $w, $h); imagejpeg($dst_r, $thumb_filename, 90); imagedestroy($img_r); imagedestroy($dst_r); } elseif ($type_orig == 3) { $img_r = imagecreatefrompng($filename); $dst_r = ImageCreateTrueColor($thumb_width, $thumb_height); imageColorAllocateAlpha($dst_r, 0, 0, 0, 127); imagealphablending($dst_r, FALSE); imagesavealpha($dst_r, TRUE); imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $thumb_width, $thumb_height, $w, $h); imagealphablending($dst_r, FALSE); imagesavealpha($dst_r, TRUE); imagepng($dst_r, $thumb_filename, 9); imagedestroy($img_r); imagedestroy($dst_r); } elseif ($type_orig == 1) { $img_r = imagecreatefromgif($filename); $dst_r = ImageCreateTrueColor($thumb_width, $thumb_height); imageColorAllocateAlpha($dst_r, 0, 0, 0, 127); imagealphablending($dst_r, FALSE); imagesavealpha($dst_r, TRUE); imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $thumb_width, $thumb_height, $w, $h); imagealphablending($dst_r, FALSE); imagesavealpha($dst_r, TRUE); imagegif($dst_r, $thumb_filename); imagedestroy($img_r); imagedestroy($dst_r); } else { ?>
get_row($wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'bwg_image WHERE id="%d"', $id)); if (!$image_data) { $image_data = new stdClass(); $image_data->image_url = (isset($_GET['image_url']) ? esc_html(stripcslashes($_GET['image_url'])) : ''); $image_data->thumb_url = (isset($_GET['thumb_url']) ? esc_html(stripcslashes($_GET['thumb_url'])) : ''); } $filename = htmlspecialchars_decode(ABSPATH . $WD_BWG_UPLOAD_DIR . $image_data->image_url, ENT_COMPAT | ENT_QUOTES); $thumb_filename = htmlspecialchars_decode(ABSPATH . $WD_BWG_UPLOAD_DIR . $image_data->thumb_url, ENT_COMPAT | ENT_QUOTES); copy(str_replace('/thumb/', '/.original/', $thumb_filename), $filename); list($width_orig, $height_orig, $type_orig) = getimagesize($filename); $percent = $width_orig / $thumb_width; $thumb_height = $height_orig / $percent; @ini_set('memory_limit', '-1'); if ($type_orig == 2) { $img_r = imagecreatefromjpeg($filename); $dst_r = ImageCreateTrueColor($thumb_width, $thumb_height); imagecopyresampled($dst_r, $img_r, 0, 0, 0, 0, $thumb_width, $thumb_height, $width_orig, $height_orig); imagejpeg($dst_r, $thumb_filename, 100); imagedestroy($img_r); imagedestroy($dst_r); } elseif ($type_orig == 3) { $img_r = imagecreatefrompng($filename); $dst_r = ImageCreateTrueColor($thumb_width, $thumb_height); imageColorAllocateAlpha($dst_r, 0, 0, 0, 127); imagealphablending($dst_r, FALSE); imagesavealpha($dst_r, TRUE); imagecopyresampled($dst_r, $img_r, 0, 0, 0, 0, $thumb_width, $thumb_height, $width_orig, $height_orig); imagealphablending($dst_r, FALSE); imagesavealpha($dst_r, TRUE); imagepng($dst_r, $thumb_filename, 9); imagedestroy($img_r); imagedestroy($dst_r); } elseif ($type_orig == 1) { $img_r = imagecreatefromgif($filename); $dst_r = ImageCreateTrueColor($thumb_width, $thumb_height); imageColorAllocateAlpha($dst_r, 0, 0, 0, 127); imagealphablending($dst_r, FALSE); imagesavealpha($dst_r, TRUE); imagecopyresampled($dst_r, $img_r, 0, 0, 0, 0, $thumb_width, $thumb_height, $width_orig, $height_orig); imagealphablending($dst_r, FALSE); imagesavealpha($dst_r, TRUE); imagegif($dst_r, $thumb_filename); imagedestroy($img_r); imagedestroy($dst_r); } @ini_restore('memory_limit'); } public function rotate() { global $WD_BWG_UPLOAD_DIR; $popup_width = ((int) (isset($_GET['width']) ? esc_html($_GET['width']) : '650')) - 30; $image_width = $popup_width - 40; $popup_height = ((int) (isset($_GET['height']) ? esc_html($_GET['height']) : '500')) - 55; $image_height = $popup_height - 70; $image_id = (isset($_GET['image_id']) ? esc_html($_GET['image_id']) : '0'); $edit_type = (isset($_POST['edit_type']) ? esc_html($_POST['edit_type']) : ''); $brightness_val = (isset($_POST['brightness_val']) ? esc_html($_POST['brightness_val']) : 0); $contrast_val = (isset($_POST['contrast_val']) ? esc_html($_POST['contrast_val']) : 0); if (isset($_GET['image_url'])) { $image_data = new stdClass(); $image_data->image_url = (isset($_GET['image_url']) ? esc_html(stripcslashes($_GET['image_url'])) : ''); $image_data->thumb_url = (isset($_GET['thumb_url']) ? esc_html(stripcslashes($_GET['thumb_url'])) : ''); $filename = htmlspecialchars_decode(ABSPATH . $WD_BWG_UPLOAD_DIR . $image_data->image_url, ENT_COMPAT | ENT_QUOTES); $thumb_filename = htmlspecialchars_decode(ABSPATH . $WD_BWG_UPLOAD_DIR . $image_data->thumb_url, ENT_COMPAT | ENT_QUOTES); $form_action = add_query_arg(array('action' => 'editThumb', 'type' => 'rotate', 'image_id' => $image_id, 'image_url' => $image_data->image_url, 'thumb_url' => $image_data->thumb_url, 'width' => '650', 'height' => '500', 'TB_iframe' => '1'), admin_url('admin-ajax.php')); } else { $image_data = $this->model->get_image_data($image_id); $image_data->image_url = stripcslashes($image_data->image_url); $filename = htmlspecialchars_decode(ABSPATH . $WD_BWG_UPLOAD_DIR . $image_data->image_url, ENT_COMPAT | ENT_QUOTES); $thumb_filename = htmlspecialchars_decode(ABSPATH . $WD_BWG_UPLOAD_DIR . $image_data->thumb_url, ENT_COMPAT | ENT_QUOTES); $form_action = add_query_arg(array('action' => 'editThumb', 'type' => 'rotate', 'image_id' => $image_id, 'width' => '650', 'height' => '500', 'TB_iframe' => '1'), admin_url('admin-ajax.php')); } @ini_set('memory_limit', '-1'); list($width_rotate, $height_rotate, $type_rotate) = getimagesize($filename); if ($edit_type == '270' || $edit_type == '90') { if ($type_rotate == 2) { $source = imagecreatefromjpeg($filename); $thumb_source = imagecreatefromjpeg($thumb_filename); $rotate = imagerotate($source, $edit_type, 0); $thumb_rotate = imagerotate($thumb_source, $edit_type, 0); imagejpeg($thumb_rotate, $thumb_filename, 90); imagejpeg($rotate, $filename, 100); imagedestroy($source); imagedestroy($rotate); imagedestroy($thumb_source); imagedestroy($thumb_rotate); } elseif ($type_rotate == 3) { $source = imagecreatefrompng($filename); $thumb_source = imagecreatefrompng($thumb_filename); imagealphablending($source, FALSE); imagealphablending($thumb_source, FALSE); imagesavealpha($source, TRUE); imagesavealpha($thumb_source, TRUE); $rotate = imagerotate($source, $edit_type, imageColorAllocateAlpha($source, 0, 0, 0, 127)); $thumb_rotate = imagerotate($thumb_source, $edit_type, imageColorAllocateAlpha($source, 0, 0, 0, 127)); imagealphablending($rotate, FALSE); imagealphablending($thumb_rotate, FALSE); imagesavealpha($rotate, TRUE); imagesavealpha($thumb_rotate, TRUE); imagepng($rotate, $filename, 9); imagepng($thumb_rotate, $thumb_filename, 9); imagedestroy($source); imagedestroy($rotate); imagedestroy($thumb_source); imagedestroy($thumb_rotate); } elseif ($type_rotate == 1) { $source = imagecreatefromgif($filename); $thumb_source = imagecreatefromgif($thumb_filename); imagealphablending($source, FALSE); imagealphablending($thumb_source, FALSE); imagesavealpha($source, TRUE); imagesavealpha($thumb_source, TRUE); $rotate = imagerotate($source, $edit_type, imageColorAllocateAlpha($source, 0, 0, 0, 127)); $thumb_rotate = imagerotate($thumb_source, $edit_type, imageColorAllocateAlpha($source, 0, 0, 0, 127)); imagealphablending($rotate, FALSE); imagealphablending($thumb_rotate, FALSE); imagesavealpha($rotate, TRUE); imagesavealpha($thumb_rotate, TRUE); imagegif($rotate, $filename); imagegif($thumb_rotate, $thumb_filename); imagedestroy($source); imagedestroy($rotate); imagedestroy($thumb_source); imagedestroy($thumb_rotate); } } elseif ($edit_type == 'vertical' || $edit_type == 'horizontal' || $edit_type == 'both') { function bwg_image_flip($imgsrc, $mode) { $width = imagesx($imgsrc); $height = imagesy($imgsrc); $src_x = 0; $src_y = 0; $src_width = $width; $src_height = $height; switch ($mode) { case 'vertical': $src_y = $height - 1; $src_height = -$height; break; case 'horizontal': $src_x = $width - 1; $src_width = -$width; break; case 'both': $src_x = $width - 1; $src_y = $height - 1; $src_width = -$width; $src_height = -$height; break; default: return $imgsrc; } $trans_colour = imageColorAllocateAlpha($imgsrc, 0, 0, 0, 127); $imgdest = imagecreatetruecolor($width, $height); imagefill($imgdest, 0, 0, $trans_colour); if (imagecopyresampled($imgdest, $imgsrc, 0, 0, $src_x, $src_y , $width, $height, $src_width, $src_height)) { return $imgdest; } return $imgsrc; } if ($type_rotate == 2) { $source = imagecreatefromjpeg($filename); $flip = bwg_image_flip($source, $edit_type); imagejpeg($flip, $filename, 100); $thumb_source = imagecreatefromjpeg($thumb_filename); $thumb_flip = bwg_image_flip($thumb_source, $edit_type); imagejpeg($thumb_flip, $thumb_filename, 90); imagedestroy($source); imagedestroy($flip); imagedestroy($thumb_source); imagedestroy($thumb_flip); } elseif ($type_rotate == 3) { $source = imagecreatefrompng($filename); $thumb_source = imagecreatefrompng($thumb_filename); imagealphablending($source, FALSE); imagealphablending($thumb_source, FALSE); imagesavealpha($source, TRUE); imagesavealpha($thumb_source, TRUE); $flip = bwg_image_flip($source, $edit_type); $thumb_flip = bwg_image_flip($thumb_source, $edit_type); imagealphablending($flip, FALSE); imagealphablending($thumb_flip, FALSE); imagesavealpha($flip, TRUE); imagesavealpha($thumb_flip, TRUE); imagepng($flip, $filename, 9); imagepng($thumb_flip, $thumb_filename, 9); imagedestroy($source); imagedestroy($flip); imagedestroy($thumb_source); imagedestroy($thumb_flip); } elseif ($type_rotate == 1) { $source = imagecreatefromgif($filename); $thumb_source = imagecreatefromgif($thumb_filename); imagealphablending($source, FALSE); imagealphablending($thumb_source, FALSE); imagesavealpha($source, TRUE); imagesavealpha($thumb_source, TRUE); $flip = bwg_image_flip($source, $edit_type); $thumb_flip = bwg_image_flip($thumb_source, $edit_type); imagealphablending($flip, FALSE); imagealphablending($thumb_flip, FALSE); imagesavealpha($flip, TRUE); imagesavealpha($thumb_flip, TRUE); imagegif($flip, $filename); imagegif($thumb_flip, $thumb_filename); imagedestroy($source); imagedestroy($flip); imagedestroy($thumb_source); imagedestroy($thumb_flip); } } elseif ($edit_type == 'brightness' || $edit_type == 'contrast' || $edit_type == 'grayscale' || $edit_type == 'negative' || $edit_type == 'remove' || $edit_type == 'emboss' || $edit_type == 'smooth') { switch ($edit_type) { case 'brightness' : $img_filter_type = IMG_FILTER_BRIGHTNESS; $ratio = $brightness_val; break; case 'contrast' : $img_filter_type = IMG_FILTER_CONTRAST; $ratio = $contrast_val; break; case 'grayscale' : $img_filter_type = IMG_FILTER_GRAYSCALE; $ratio = ''; break; case 'negative' : $img_filter_type = IMG_FILTER_NEGATE; $ratio = ''; break; case 'remove' : $img_filter_type = IMG_FILTER_MEAN_REMOVAL; $ratio = ''; break; case 'emboss' : $img_filter_type = IMG_FILTER_EMBOSS; $ratio = ''; break; case 'smooth' : $img_filter_type = IMG_FILTER_SMOOTH; $ratio = 30; break; default: return; } $img_type = $type_rotate; if ($img_type == 2) { $source = imagecreatefromjpeg($filename); $thumb_source = imagecreatefromjpeg($thumb_filename); imagefilter($source, $img_filter_type, $ratio); imagefilter($thumb_source, $img_filter_type, $ratio); imagejpeg($source, $filename, 100); imagejpeg($thumb_source, $thumb_filename, 90); imagedestroy($source); imagedestroy($thumb_source); } elseif ($img_type == 3) { $source = imagecreatefrompng($filename); $thumb_source = imagecreatefrompng($thumb_filename); imagealphablending($source, FALSE); imagealphablending($thumb_source, FALSE); imagesavealpha($source, TRUE); imagesavealpha($thumb_source, TRUE); imagefilter($source, $img_filter_type, $ratio); imagefilter($thumb_source, $img_filter_type, $ratio); imagepng($source, $filename, 9); imagepng($thumb_source, $thumb_filename, 9); imagedestroy($source); imagedestroy($thumb_source); } elseif ($img_type == 1) { $source = imagecreatefromgif($filename); $thumb_source = imagecreatefromgif($thumb_filename); imagealphablending($source, FALSE); imagealphablending($thumb_source, FALSE); imagesavealpha($source, TRUE); imagesavealpha($thumb_source, TRUE); imagefilter($source, $img_filter_type, $ratio); imagefilter($thumb_source, $img_filter_type, $ratio); imagegif($source, $filename); imagegif($thumb_source, $thumb_filename); imagedestroy($source); imagedestroy($thumb_source); } } elseif ($edit_type == 'sepia' || $edit_type == 'dark_slate_grey' || $edit_type == 'saturate') { switch($edit_type) { case 'sepia' : $img_filter_type = IMG_FILTER_COLORIZE; $red = 112; $green = 66; $blue = 20; break; case 'dark_slate_grey' : $img_filter_type = IMG_FILTER_COLORIZE; $red = 47; $green = 79; $blue = 79; break; case 'saturate' : $img_filter_type = IMG_FILTER_COLORIZE; $red = 236; $green = 40; $blue = 41; break; default: return; } $img_type = $type_rotate; if ($img_type == 2) { $source = imagecreatefromjpeg($filename); $thumb_source = imagecreatefromjpeg($thumb_filename); imagefilter($source, $img_filter_type, $red, $green, $blue); imagefilter($thumb_source, $img_filter_type, $red, $green, $blue); imagejpeg($source, $filename, 100); imagejpeg($thumb_source, $thumb_filename, 90); imagedestroy($source); imagedestroy($thumb_source); } elseif ($img_type == 3) { $source = imagecreatefrompng($filename); $thumb_source = imagecreatefrompng($thumb_filename); imagealphablending($source, FALSE); imagealphablending($thumb_source, FALSE); imagesavealpha($source, TRUE); imagesavealpha($thumb_source, TRUE); imagefilter($source, $img_filter_type, $red, $green, $blue); imagefilter($thumb_source, $img_filter_type, $red, $green, $blue); imagepng($source, $filename, 9); imagepng($thumb_source, $thumb_filename, 9); imagedestroy($source); imagedestroy($thumb_source); } elseif ($img_type == 1) { $source = imagecreatefromgif($filename); $thumb_source = imagecreatefromgif($thumb_filename); imagealphablending($source, FALSE); imagealphablending($thumb_source, FALSE); imagesavealpha($source, TRUE); imagesavealpha($thumb_source, TRUE); imagefilter($source, $img_filter_type, $red, $green, $blue); imagefilter($thumb_source, $img_filter_type, $red, $green, $blue); imagegif($source, $filename); imagegif($thumb_source, $thumb_filename); imagedestroy($source); imagedestroy($thumb_source); } } elseif ($edit_type == 'recover') { global $wpdb; $id = ((isset($_POST['image_id'])) ? (int) esc_html(stripslashes($_POST['image_id'])) : 0); $options = $wpdb->get_row('SELECT * FROM ' . $wpdb->prefix . 'bwg_option WHERE id=1'); $thumb_width = $options->thumb_width; $thumb_height = $options->thumb_height; $this->recover_image($id, $thumb_width, $thumb_height); } @ini_restore('memory_limit'); wp_print_scripts('jquery'); wp_print_scripts('jquery-ui-widget'); wp_print_scripts('jquery-ui-slider'); ?>

0
0