当前位置: 首页>>代码示例>>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;未经允许,请勿转载。