當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ImageHelper::IResize方法代碼示例

本文整理匯總了PHP中ImageHelper::IResize方法的典型用法代碼示例。如果您正苦於以下問題:PHP ImageHelper::IResize方法的具體用法?PHP ImageHelper::IResize怎麽用?PHP ImageHelper::IResize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ImageHelper的用法示例。


在下文中一共展示了ImageHelper::IResize方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: load_posts_callback

 public static function load_posts_callback()
 {
     global $wpdb;
     $_POST = stripslashes_deep($_POST);
     $post_id = intval($_POST['post_id']);
     $img = trim($_POST['img_name']);
     $opt_key = strtolower(trim($_POST['opt_key']));
     $btn = preg_replace('/[_]+/i', ' ', $opt_key);
     $btn = ucwords($btn);
     $gotIt = false;
     if ($post_id && !empty($img) && !empty($opt_key)) {
         $fn = "display_{$opt_key}_list";
         if (method_exists('MetaSeo_Image_List_Table', $fn)) {
             //Get list of posts contain this image and its clones
             $posts = ImageHelper::_get_post_list($post_id, $opt_key);
             if (count($posts) > 0) {
                 $img_counter = 0;
                 //Now the time to resize the images
                 if ($opt_key === 'resize_image') {
                     $upload_dir = wp_upload_dir();
                     $metaseo_sizes_optional = get_post_meta($post_id, '_metaseo_sizes_optional', TRUE);
                     if (!is_array($metaseo_sizes_optional)) {
                         $metaseo_sizes_optional = array();
                     }
                     $attachment_meta_data = wp_get_attachment_metadata($post_id);
                     foreach ($posts as &$post) {
                         foreach ($post['img_after_optm'] as &$img) {
                             $img_counter++;
                             $destination = $upload_dir['basedir'] . '/' . $img['path'];
                             if (@ImageHelper::IResize($img['src_origin'], $img['width'], $img['height'], $destination)) {
                                 $size = filesize($destination) / 1024;
                                 if ($size > 1024) {
                                     $size = $size / 1024;
                                     $sizes = 'MB';
                                 } else {
                                     $sizes = 'KB';
                                 }
                                 $size = @round($size, 1);
                                 $img['size'] = $size;
                                 $img['sizes'] = $sizes;
                             }
                             $kpart = ImageHelper::IGetPart($img['path']);
                             $key = preg_replace('/\\-(\\d+)x(\\d+)$/i', '-metaseo${1}${2}', $kpart->name);
                             $key = strtolower($key);
                             $file = substr($img['path'], strrpos($img['path'], '/') + 1);
                             if (!in_array($key, array_keys($metaseo_sizes_optional))) {
                                 $metaseo_sizes_optional[$key] = array('url' => $img['src'], 'width' => $img['width'], 'height' => $img['height'], 'orientation' => 'landscape');
                             }
                             if (!isset($attachment_meta_data['sizes'][$key])) {
                                 $attachment_meta_data['sizes'][$key] = array('file' => $file, 'width' => $img['width'], 'height' => $img['height'], 'mime-type' => 'image/jpeg');
                             }
                         }
                     }
                     wp_update_attachment_metadata($post_id, $attachment_meta_data);
                     update_post_meta($post_id, '_metaseo_sizes_optional', $metaseo_sizes_optional);
                 } elseif ($opt_key === 'fix_metas') {
                     $toEdit = false;
                     $pIDs = array();
                     foreach ($posts as $ID => &$post) {
                         $img_counter += count($post['meta']);
                         foreach ($post['meta'] as $order => $meta) {
                             if ($meta['type']['alt'] == '' || $meta['type']['title'] == '') {
                                 $toEdit = true;
                             }
                             if ($meta['type']['alt'] != '' && $meta['type']['title'] != '') {
                                 $pIDs[$ID][] = $order;
                             }
                         }
                     }
                     if ($toEdit === true) {
                         foreach ($pIDs as $ID => $orders) {
                             foreach ($orders as $order) {
                                 unset($posts[$ID]['meta'][$order]);
                                 if ($img_counter > 0) {
                                     $img_counter--;
                                 }
                             }
                             if (empty($posts[$ID]['meta'])) {
                                 unset($posts[$ID]);
                             }
                         }
                     }
                 }
                 //-----------------------------
             }
         }
     }
     //This is a bit crazy but could give more exact information
     if (count($posts) > 1) {
         $p = ' in ' . count($posts) . ' posts ';
     } else {
         $p = '';
     }
     if (isset($img_counter) and $img_counter > 1) {
         $im = ' images ';
     } else {
         if (!isset($img_counter)) {
             $img_counter = 0;
         }
         $im = ' image ';
//.........這裏部分代碼省略.........
開發者ID:rainevincent,項目名稱:wp-meta-seo,代碼行數:101,代碼來源:class.metaseo-image-list-table.php


注:本文中的ImageHelper::IResize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。