2016-12-07 6 views
2

私は、PHPを使用して画像に透かしとして透明なロゴを追加しています。しかし、その結果、ロゴの品質は悪いです(その下にあるイメージは高品質なので、透かしだけです)。これは私が(その最後の3行程度)を使用するコードです:ウォーターマークとしてのロゴの追加、透かしの品質の悪い

header("Content-Type: image/png"); 

$photo = imagecreatefromjpeg('photos/'.$photo['image']); 
$height = imagesx($photo); 
$width = imagesx($photo); 
if ($width > $_POST['width']) { 
    $r = $width/$_POST['width']; 

    $newwidth = $width/$r; 
    $newheight = $height/$r; 
} 
$image = imagecreatetruecolor($width, $height); 

$image2 = imagecopyresampled($image, $photo, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 

$position = explode(" ", $_POST['background']); 

$image3 = imagecrop($image, [ 
    'x' => str_replace(array('-', 'px'), array('', ''), $position[0]), 
    'y' => str_replace(array('-', 'px'), array('', ''), $position[1]), 
    'width' => $_POST['width'], 
    'height' => $_POST['height'] 
]); 
$stamp = imagecreatefrompng('img/logo.png'); 
imagecopyresized($image3, $stamp, 0, 0, 0, 0, 147, 50, imagesx($stamp), imagesy($stamp)); 
imagepng($image3, "created/".time().".png", 9); 
+0

あなたの本当の質問は何ですか? – Blueblazer172

+0

なぜimagecopyresizedを使用して透かしの品質が悪いのですか? –

答えて

0

imagecopyresizedは、コピーして、規模やイメージます。これは、よりピクセル化された結果をもたらす傾向がある、かなり原始的なアルゴリズムを使用します。

より良い品質であるため、簡単な例:

<?php 
// The file 
$filename = 'test.jpg'; 
$percent = 0.5; 

// Content type 
header('Content-type: image/jpeg'); 

// Get new dimensions 
list($width, $height) = getimagesize($filename); 
$new_width = $width * $percent; 
$new_height = $height * $percent; 

// Resample 
$image_p = imagecreatetruecolor($new_width, $new_height); 
$image = imagecreatefromjpeg($filename); 
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); 

// Output 
imagejpeg($image_p, null, 100); 
?> 

あなたがこの記事で1-100からの画像のhere

0

使用品質を見ている必要があります。

imagejpeg($image, $new_image_name, 99); 
関連する問題