• Добавляю на сайт картинки таким макаром:

    get_img_theme($full_filename,50,50);
        get_img_theme($full_filename,100,100);
        get_img_theme($full_filename,250,250);
        get_img_theme($full_filename,500,500);
    
    function get_img_theme($url, $width, $height){
        $img_name=explode('/', $url);
        $file_url='/wp-content/uploads/'.$img_name[count($img_name)-3].'/'.$img_name[count($img_name)-2].'/';
        $file_name=explode('.', $img_name[count($img_name)-1]);
        $file_name=$file_name[0].'-'.$width.'x'.$height.'.'.$file_name[1];
        if(file_exists($file_url.$file_name))
            return $file_url.$file_name;
        else{
            $image = wp_get_image_editor(ABSPATH.$file_url.$img_name[count($img_name)-1]);
            if ( ! is_wp_error($image)){
                $image->resize($width, $height, true );
                $image->save(ABSPATH.$file_url.$file_name);
                return $file_url.$file_name;
            }
        }
    }
    
        $attachments = get_children( array('post_parent' => $post_ID, 'post_type' => 'attachment', 'post_mime_type' => 'image') );
    	if(!$attachments) {
    		$wp_filetype = wp_check_filetype($filename, null);
    		$attachment = array(
    			'guid' => $url_filename,
    			'post_mime_type' => $wp_filetype['type'],
    			'post_title' => sanitize_file_name($filename),
    			'post_content' => '',
    			'post_status' => 'inherit',
    			'post_author' => 1,
    		);
    		$attach_id = wp_insert_attachment($attachment, $url_filename, $post_ID);
    		//require_once(ABSPATH . 'wp-admin/includes/image.php');
    		$attach_data = wp_generate_attachment_metadata($attach_id, $filename);
    		wp_update_attachment_metadata($attach_id, $attach_data);
    	}
        if($attach_id>0){
    	        	//if($type=='1')
    	        	 add_post_meta($post_ID, '_thumbnail_id', $attach_id, true);
    	}

    Но в медиафайле нет инфы об обрезанных картинках, а только об основной, как это лечиться?

Просмотр 1 ответа (всего 1)
Просмотр 1 ответа (всего 1)
  • Тема «Как добавить в медиафайл инфу о фото» закрыта для новых ответов.