2012-01-26 24 views
2

画像をある程度切り抜こうとしています。ワードプレスで特定のサイズにクロップ画像を表示

私は

add_image_size('other', 105, 70, true); 
$imageString.= '<div><a href="' . $linkstring . '">' . get_the_post_thumbnail($post->ID, 'other;) . '</a></div>'; 

を使用して試してみました。しかし、その正確な大きさにトリミングしていないようです。

Ides?

答えて

9

通常、画像サイズをfunctions.phpファイルに追加します。

//post thumbnail support 
add_action('after_setup_theme', 'theme_setup'); 

function theme_setup() { 
     if (function_exists('add_theme_support')) { 
     add_image_size('other', 105, 70, true); 
    } 
} 

その後、すべての新しい画像アップロードのために、wordpressはそのサイズで画像を作成します。

あなたは、すでにアップロードされた画像のためにこれらの画像サイズを作成したい私の経験でhttp://wordpress.org/extend/plugins/regenerate-thumbnails/

0

画像のサイズ変更やトリミングに関する機能はすべてmedia.phpにあります。

たとえば、クロップの寸法を示すimage_resize_dimensionsの読み取りを開始します。これらの次元はimagecopyresampledで使用できます。

1

を見てみると、あなたがadd_image_sizeを追加したカスタムの画像サイズを使用している場合、get_the_post_thumbnailは常に動作しません。

私はadd_image_sizeを使用するためにあなたをアドバイスしますが、このようなwp_get_attachment_image_src throught画像を取得したい:

$imageurl = wp_get_attachment_image_src($attachment->ID, "other"); 

$imageString.= '<div><a href="' . $linkstring . '"><img src="' . $imageurl[0] . '"/></a></div>'; 
+1

wp_get_attachment_image_srcがパラメータとしてポストIDを負いません。アタッチメントIDが必要です。 http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src – lamarant

+0

ありがとう、あなたの訂正を反映しました;) –

関連する問題