-2
だから私はディレクトリからすべてのファイルを撮影するコードを持っていて、透かしを入れて別のディレクトリに入れます。テキストでイメージにウォーターマークを付ける方法を知りたいのですが、私はimagettftext()を使ってこれを試みましたが、運はありませんでした。ここでテキストで画像に透かしを入れるにはどうすればよいですか?
は、作業コードは、事前に
<?php
//Source folder where all images are placed
$source="myimages";
//Destination folder where all images with watermark will be copied
$destination="donewatermarks";
//Creating an image object of watermark image
$watermark=imagecreatefrompng("watermark.png");
//Margin of watermark from right and bottom of the main image
$margin_right=10;
$margin_bottom=10;
//Height ($sy) and Width ($sx) of watermark image
$sx=imagesx($watermark);
$sy=imagesy($watermark);
//Get list of images in source folder
$images=array_diff(scandir($source), array('..', '.'));
foreach($images as $image){
//Create image object of main image
$img=imagecreatefromjpeg($source.'/'.$image);
//Copying watermark image into the main image
imagecopy($img, $watermark, imagesx($img) - $sx - $margin_right,
imagesy($img) - $sy - $margin_bottom, 0, 0, $sx, $sy);
//Saving the merged image into the destination folder
imagejpeg($img, $destination.'/'.$image,100);
//Destroying the main image object
imagedestroy($img);
}
//Destroying watermark image object
imagedestroy($watermark);
?>
感謝です!ここで
は現在、エラー
<?php
//Source folder where all images are placed
$source="watermarkitems";
//Destination folder where all images with watermark will be copied
$destination="donewatermarks";
//Creating an image object of watermark image
$watermark=imagecreatefrompng("watermark.png");
//Margin of watermark from right and bottom of the main image
$margin_right=10;
$margin_bottom=10;
//Height ($sy) and Width ($sx) of watermark image
$sx=imagesx($watermark);
$sy=imagesy($watermark);
$text = 'Testing...';
//Get list of images in source folder
$images=array_diff(scandir($source), array('..', '.'));
foreach($images as $image){
//Create image object of main image
$img=imagecreatefromjpeg($source.'/'.$image);
// Add the text
imagettftext($img, 20, 0, 10, 20, $black, $font, $text);
//Saving the merged image into the destination folder
imagejpeg($img, $destination.'/'.$image,100);
header('Content-Type: image/jpg');
//Destroying the main image object
imagedestroy($img);
}
//Destroying watermark image object
imagedestroy($watermark);
?>
*ここでは作業コード* - あなたの試みは失敗しましたか?何が問題なの?マニュアルをまったく読んでいたのですか? http://php.net/manual/en/function.imagettftext.php –
@ Fred-ii-ヘッダー(Content-type:image/png)を追加すると、マニュアルを読んだことがあります。エラーメッセージが表示されます。画像を追加しないと、画像にウォーターマークが表示されずに移動します。 –
オリジナルのコードの下に試したコードとDaveの正確なエラーメッセージを投稿できますか?これはあなたの質問ではもちろん;-)私は今の私のdev pcではないが、私はそこに着くときに私はそれを見てみましょう。あなたはまた、以下の答えを与えられました、あなたはそれを試しましたか? –