回答編集履歴
2
追記
answer
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
たぶんトリミングの方でできた余白が黒くなっているんだと思います。そもそも単に画像をコピーすればいいだけなので、ImageCopyを使ってやればうまくいきましたよ。
|
1
|
+
たぶんトリミングの方でできた余白が黒くなっているんだと思います。そもそも単に画像をコピーすればいいだけなので、ImageCopyを使ってやればうまくいきましたよ。あと、image_outputの余白部分は、透明で塗りつぶしておく必要があるかと
|
2
|
-
※あと、image_outputの余白部分は、透明で塗りつぶしておく必要があるかと
|
3
2
|
|
4
3
|
```php
|
5
4
|
<?php
|
@@ -14,12 +13,14 @@
|
|
14
13
|
$image_trimming = ImageCreateTrueColor($width_trimming,$height_trimming);
|
15
14
|
$image_output = ImageCreateTrueColor($width_output,$height_output);
|
16
15
|
|
16
|
+
//ブレンドモードを無効にする
|
17
17
|
imagealphablending($image_trimming, false);
|
18
18
|
imagealphablending($image_output, false);
|
19
19
|
|
20
20
|
$transparent = imagecolorallocatealpha($image_output, 0, 0, 0, 127); // 透明度を持つ色を作成
|
21
21
|
imagefill($image_output, 0, 0, $transparent); // 塗りつぶす
|
22
22
|
|
23
|
+
//完全なアルファチャネル情報を保存するフラグをonにする
|
23
24
|
imagesavealpha($image_trimming, true);
|
24
25
|
imagesavealpha($image_output, true);
|
25
26
|
|
1
追記
answer
CHANGED
@@ -1,6 +1,34 @@
|
|
1
1
|
たぶんトリミングの方でできた余白が黒くなっているんだと思います。そもそも単に画像をコピーすればいいだけなので、ImageCopyを使ってやればうまくいきましたよ。
|
2
|
+
※あと、image_outputの余白部分は、透明で塗りつぶしておく必要があるかと
|
2
3
|
|
3
4
|
```php
|
5
|
+
<?php
|
6
|
+
$image_resource = imagecreatefrompng($outPathTrimming);
|
7
|
+
$width_resource = ImageSx($image_resource);
|
8
|
+
$height_resource = ImageSy($image_resource);
|
9
|
+
$width_trimming = ImageSx($image_resource) * $scale/100;
|
10
|
+
$height_trimming = ImageSy($image_resource) * $scale/100;
|
11
|
+
$width_output = 200;
|
12
|
+
$height_output = 200;
|
13
|
+
|
14
|
+
$image_trimming = ImageCreateTrueColor($width_trimming,$height_trimming);
|
15
|
+
$image_output = ImageCreateTrueColor($width_output,$height_output);
|
16
|
+
|
17
|
+
imagealphablending($image_trimming, false);
|
18
|
+
imagealphablending($image_output, false);
|
19
|
+
|
20
|
+
$transparent = imagecolorallocatealpha($image_output, 0, 0, 0, 127); // 透明度を持つ色を作成
|
21
|
+
imagefill($image_output, 0, 0, $transparent); // 塗りつぶす
|
22
|
+
|
23
|
+
imagesavealpha($image_trimming, true);
|
24
|
+
imagesavealpha($image_output, true);
|
25
|
+
|
26
|
+
//縮小イメージ作成
|
27
|
+
ImageCopyResampled($image_trimming, $image_resource,0,0,0,0, $width_trimming,$height_trimming,$width_resource,$height_resource);
|
28
|
+
|
4
29
|
//トリミングイメージ作成
|
5
30
|
ImageCopy($image_output, $image_trimming,($width_output - $width_trimming)/2,($height_output - $height_trimming)/2, 0,0, $width_trimming,$height_trimming);
|
31
|
+
|
32
|
+
//出力
|
33
|
+
imagepng($image_output, $outPath);
|
6
34
|
```
|