元の正方形のタイルベースの画像レンダリングが画像の切り抜きになるように、サイトを再設計しようとしています...そのグリッドパターンを取り除くために.
元の姿はこんな感じ…
これが私がやろうとしていることの大まかなモックアップです:
そこで、背景が透明な画像のサムネイルを再保存しました...犬を見せたいだけで、正方形は透明で、その下にサイトの背景が表示されます。
しかし、ページにレンダリングすると、この黒い背景になります。
私はCSSをチェックして、何らかのimgクラス、またはレンダリングされたコミックのクラスがあるかどうかを確認しました...またはブートストラップでさえ、背景色が黒に割り当てられている場所があるかどうかを確認しました(また、hexも検索しました)コード 000000) が見つかりませんでした...
次に、サムネイル作成スクリプトがpngを再サンプリングする方法に関係していることがわかりました...おそらく透明な画像の背景が黒くなっているので、imagecreatetruecolor()
どちらを責めますかreturns an image identifier representing a black image of the specified size.
。
リサンプリング後の透明度の保持に関する Cheekysoft の質問hereに従ってみましたが、うまくいきませんでした。
imagealphablending( $targetImage, false );
imagesavealpha( $targetImage, true );
サイズ変更/リサンプルする前に配置すると、透明に表示されることがわかりまし$img = imagecreatefrompng($image_file);
た...これは私が望むものです...しかし、リサンプルした後ではありません。
Thumbnailer.php コード:
<?php
#Appreciation goes to digifuzz (http://www.digifuzz.net) for help on this
$image_file = $_GET['img']; //takes in full path of image
$MAX_WIDTH = $_GET['mw'];
$MAX_HEIGHT = $_GET['mh'];
global $img;
//Check for image
if(!$image_file || $image_file == "") {
die("NO FILE.");
}
//If no max width, set one
if(!$MAX_WIDTH || $MAX_WIDTH == "") {
$MAX_WIDTH="100";
}
//if no max height, set one
if(!$MAX_HEIGHT || $MAX_HEIGHT == "") {
$MAX_HEIGHT = "100";
}
$img = null;
//create image file from 'img' parameter string
if( preg_match('/\.jpg$/',$image_file) || preg_match('/\.jpeg$/',$image_file) ){
$img = imagecreatefromjpeg($image_file);
} else {
$img = imagecreatefrompng($image_file);
}
//if image successfully loaded...
if($img) {
//get image size and scale ratio
$width = imagesx($img);
$height = imagesy($img);
//takes min value of these two
$scale = min($MAX_WIDTH/$width, $MAX_HEIGHT/$height);
//if desired new image size is less than original, output new image
if($scale < 1) {
$new_width = floor($scale * $width);
$new_height = floor($scale * $height);
$tmp_img = imagecreatetruecolor($new_width, $new_height);
//copy and resize old image to new image
imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
//replace actual image with new image
$img = $tmp_img;
}
}
//set the content type header
header('Content-Type: image/png', true);
imagealphablending( $img, false );
imagesavealpha( $img, true );
imagepng($img);
imagedestroy($img);
?>
誰でも助けることができますか?
ありがとう!