function flagCreateNewThumb() { global $wpdb; // check for correct capability if (!is_user_logged_in()) { die('-1'); } // check for correct FlAG capability if (!current_user_can('FlAG Manage gallery')) { die('-1'); } require_once dirname(dirname(__FILE__)) . '/flag-config.php'; include_once flagGallery::graphic_library(); $flag_options = get_option('flag_options'); $id = (int) $_POST['id']; $picture = flagdb::find_image($id); $x = round($_POST['x'] * $_POST['rr'], 0); $y = round($_POST['y'] * $_POST['rr'], 0); $w = round($_POST['w'] * $_POST['rr'], 0); $h = round($_POST['h'] * $_POST['rr'], 0); $thumb = new flag_Thumbnail($picture->imagePath, TRUE); $thumb->crop($x, $y, $w, $h); if ($flag_options['thumbFix']) { if ($thumb->currentDimensions['height'] > $thumb->currentDimensions['width']) { $thumb->resize($flag_options['thumbWidth'], 0); } else { $thumb->resize(0, $flag_options['thumbHeight']); } } else { $thumb->resize($flag_options['thumbWidth'], $flag_options['thumbHeight']); } if ($thumb->save($picture->thumbPath, 100)) { //read the new sizes $new_size = @getimagesize($picture->thumbPath); $size['width'] = $new_size[0]; $size['height'] = $new_size[1]; // add them to the database flagdb::update_image_meta($picture->pid, array('thumbnail' => $size)); echo "OK"; } else { header('HTTP/1.1 500 Internal Server Error'); echo "KO"; } exit; }
/** * flagAdmin::createThumbnail() - function to create or recreate a thumbnail * * @param object | int $image contain all information about the image or the id * @return string result code */ static function create_thumbnail($image) { global $flag; if (!class_exists('flag_Thumbnail')) { require_once flagGallery::graphic_library(); } if (is_numeric($image)) { $image = flagdb::find_image($image); } if (!is_object($image)) { return __('Object didn\'t contain correct data', 'flag'); } // check for existing thumbnail if (file_exists($image->thumbPath)) { if (!is_writable($image->thumbPath)) { return $image->filename . __(' is not writeable ', 'flag'); } } $thumb = new flag_Thumbnail($image->imagePath, TRUE); $img_size = @getimagesize($image->imagePath); // skip if file is not there if (!$thumb->error) { if ($flag->options['thumbFix']) { // check for portrait format if ($flag->options['thumbWidth'] / $flag->options['thumbHeight'] > $img_size[0] / $img_size[1]) { // first resize to the wanted width $thumb->resize($flag->options['thumbWidth'], 0); // get optimal y startpos $ypos = ($thumb->currentDimensions['height'] - $flag->options['thumbHeight']) / 2; $thumb->crop(0, $ypos, $flag->options['thumbWidth'], $flag->options['thumbHeight']); } else { // first resize to the wanted height $thumb->resize(0, $flag->options['thumbHeight']); // get optimal x startpos $xpos = ($thumb->currentDimensions['width'] - $flag->options['thumbWidth']) / 2; $thumb->crop($xpos, 0, $flag->options['thumbWidth'], $flag->options['thumbHeight']); } //this create a thumbnail but keep ratio settings } else { $thumb->resize($flag->options['thumbWidth'], $flag->options['thumbHeight']); } // save the new thumbnail $thumb->save($image->thumbPath, $flag->options['thumbQuality']); flagAdmin::chmod($image->thumbPath); //read the new sizes $new_size = @getimagesize($image->thumbPath); $size['width'] = $new_size[0]; $size['height'] = $new_size[1]; // add them to the database flagdb::update_image_meta($image->pid, array('thumbnail' => $size)); } $thumb->destruct(); if (!empty($thumb->errmsg)) { return $image->filename . ' (Error : ' . $thumb->errmsg . ')'; } // success return '1'; }