2011-07-11 9 views
2

私は透明なpngイメージを持っています。それから1x1の透明イメージにクロップしてコピーします。スクリプトを使ってPNGイメージを変更するには?

「1x1透明画像に切り抜く」の部分に固執しています。

私は既存のイメージを変更するか、新しいイメージを作成して既存のイメージを上書きできます。私は両方のオプションが動作すると信じています。私はちょうど1分1ピクセルの透明なpng画像でどちらかをやり終える方法がわかりません。

ご迷惑をおかけして申し訳ございません。

function convertImage(){ 
    $file1 = "../myfolder/image.png"; 
    $file2 = "../myfolder/image-previous.png"; 

    if (!file_exists($file2)) 
     { 
     //make a copy of image.png and name the resulting file image-previous.png 
     imagecopy($file2, $file1); 

     // convert image.png to a 1x1 pixel transparent png 
     // OR 
     // create a new 1x1 transparent png and overwrite image.png with it 
     ??? 

     } 
} 
+0

'IMAGECOPY()'ファイルでは動作しません。 'imagecreatfrom ...()'を使用してGDイメージハンドルで動作します。ファイルをコピーしたい場合は、 'copy()' –

+0

ermを使用して、1x1px透明PNGに変換しますか?あなたがそれに詰め込むと思われる詳細はどれくらいですか? –

+0

@ケリン、none。それが目的です。レイアウトからイメージの視覚的な部分を効果的に削除しますが、一時的な「隠れた」設定として設計されています。 –

答えて

2

PHPが持っているimagecopyresizedメソッドを使用してください。

More information about imagecopyresized

例:

$image_stats = GetImageSize("/picture/$photo_filename");  
$imagewidth = $image_stats[0];  
$imageheight = $image_stats[1];  
$img_type = $image_stats[2];  
$new_w = $cfg_thumb_width;  
$ratio = ($imagewidth/$cfg_thumb_width);  
$new_h = round($imageheight/$ratio); 

// if this is a jpeg, resize as a jpeg 
if ($img_type=="2") {  
    $src_img = imagecreatefromjpeg("/picture/$photo_filename");  
    $dst_img = imagecreate($new_w,$new_h);  
    imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img)); 

    imagejpeg($dst_img, "/picture/$photo_filename"); 
} 
// if image is a png, copy it as a png 
else if ($img_type=="3") { 
    $dst_img=ImageCreate($new_w,$new_h); 
    $src_img=ImageCreateFrompng("/picture/$photo_filename"); 
    imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img)); 

    imagepng($dst_img, "/picture/$photo_filename"); 
} 
else ... 
+0

ありがとうジュール。これは役に立ちます! –

+0

あなたは大歓迎です! – Jules

関連する問題