Php代码args中的图像尺寸

时间:2017-01-13 作者:nakedart

是否有办法使用此php代码将图像上载限制为400x400px?

if(mandatory_pics_for_jbs == "yes")
        {

                $args = array(
                \'order\'          => \'ASC\',
                \'orderby\'        => \'post_date\',
                \'post_type\'      => \'attachment\',
                \'post_parent\'    => $pid,
                \'post_mime_type\' => \'image\',
                \'numberposts\'    => -1,
                ); $i = 0;

                $attachments = get_posts($args);
                if(count($attachments) == 0)
                {
                    $adOK = 0; $post_new_error[\'job_img\']       = __(\'You need to upload at least one image for your Design!\'); 
                }

        }

1 个回复
SO网友:nakedart

我使用了这段代码,但什么都没发生,也许有一些小细节遗漏了,谢谢你,谁能帮我

$mimes = array( \'image/jpeg\');
                if( !in_array( $file[\'type\'], $mimes ) )
                    return $file;
                $image = getimagesize($file[\'tmp_name\']);

                $minimum = array(
                    \'width\' => \'400\',
                    \'height\' => \'400\'
                ); 
                $maximum = array( 
                    \'width\' => \'400\',
                    \'height\' => \'400\'
                );
                $image_width = $image[0];
                $image_height = $image[1];

                if ( $image_width < $minimum[\'width\'] || $image_height < $minimum[\'height\'] ) {
                    $adOK = 0; $post_new_error[\'job_img\']       = __(\'Image dimension too small\');                      
                }
                elseif ( $image_width > $maximum[\'width\'] || $image_height > $maximum[\'height\'] ) {
                    $adOK = 0; $post_new_error[\'job_img\']       = __(\'Image dimension too big\');        
                }

相关推荐

无法在模板函数.php中使用IS_HOME

我试图在标题中加载一个滑块,但只在主页上加载。如果有帮助的话,我正在使用Ultralight模板。我正在尝试(在template functions.php中)执行以下操作:<?php if ( is_page( \'home\' ) ) : ?> dynamic_sidebar( \'Homepage Widget\' ); <?php endif; ?> 但这行不通。现在,通过快速的google,我似乎需要将请