diff --git a/docs/docker-php.md b/docs/docker-php.md index 391b2a0..d6d1cf5 100644 --- a/docs/docker-php.md +++ b/docs/docker-php.md @@ -73,4 +73,18 @@ RUN docker-php-ext-configure gd \ --with-jpeg \ && docker-php-ext-install gd +``` + + +### ImageMagickの対応 + +```Dockerfile +RUN apk add --no-cache \ + imagemagick \ + imagemagick-dev \ + libheif \ + + +RUN pecl install imagick \ + && docker-php-ext-enable imagick ``` \ No newline at end of file diff --git a/src/example/ImageEdit.php b/src/example/ImageEdit.php index cd6001c..2829ae7 100644 --- a/src/example/ImageEdit.php +++ b/src/example/ImageEdit.php @@ -1,8 +1,4 @@ - - + 画像変換ツール + + - -

画像変換ツール

-
-
-

- -

- - × -

- -
+
+
+
+

画像変換ツール

+
+
+ + +
+
+ + +
+
+ +
+ + × + +
+
+ +
- エラー: {$result['error']}

"; - } else { - $base64 = base64_encode($result['data']); - echo "

変換結果:

"; - echo "
"; - echo "画像を保存"; - } - } - ?> + エラー: {$result['error']}
"; + } else { + $base64 = base64_encode($result['data']); + echo "

変換結果:

"; + echo "変換画像"; + echo "
画像を保存
"; + } + } + ?> +
+
+ - - \ No newline at end of file + diff --git a/src/example/ImageEditWithHEIC.php b/src/example/ImageEditWithHEIC.php index 70b39d3..03fc8e0 100644 --- a/src/example/ImageEditWithHEIC.php +++ b/src/example/ImageEditWithHEIC.php @@ -5,15 +5,12 @@ function canUseImagick(): bool { function loadImage($filePath): array { $mime = mime_content_type($filePath); - - // HEIC対応(Imagick前提) if (strpos($mime, 'heic') !== false || strpos($mime, 'heif') !== false) { if (!canUseImagick()) return ['error' => 'HEIC形式にはImagickが必要です']; $image = new Imagick($filePath); return ['image' => $image]; } - // 通常の画像読み込み(GD) $imgStr = file_get_contents($filePath); $gdImage = @imagecreatefromstring($imgStr); if (!$gdImage) return ['error' => '画像の読み込みに失敗しました']; @@ -62,76 +59,99 @@ function resizeAndCropGD($img, $maxW, $maxH, $cropX, $cropY, $cropW, $cropH): Gd ?> - + 画像変換ツール + -

画像変換ツール

-
-
-

+
+
+
+

画像変換ツール

+ +
+ + +
- -

+
+ + +
- -

+
+ + +
- - × -

+
+ +
+ + × + +
+
-
- - - -

+
+ +
+
+
+
+
+
+
- - + + -エラー: {$result['error']}

"; - } else { - if (isset($result['gd'])) { - $img = resizeAndCropGD($result['gd'], $maxW, $maxH, $cropX, $cropY, $cropW, $cropH); - $out = gdToBlob($img, $format, $transparent); - } elseif (isset($result['image'])) { - $image = $result['image']; - if ($cropW && $cropH) { - $image->cropImage($cropW, $cropH, $cropX, $cropY); + if (isset($result['error'])) { + echo "
エラー: {$result['error']}
"; + } else { + if (isset($result['gd'])) { + $img = resizeAndCropGD($result['gd'], $maxW, $maxH, $cropX, $cropY, $cropW, $cropH); + $out = gdToBlob($img, $format, $transparent); + } elseif (isset($result['image'])) { + $image = $result['image']; + if ($cropW && $cropH) { + $image->cropImage($cropW, $cropH, $cropX, $cropY); + } + $image->scaleImage($maxW, $maxH, true); + $out = imagickToBlob($image, $format); + } + + $base64 = base64_encode($out['data']); + $mime = $out['mime']; + + echo "

変換結果:

"; + echo "変換画像"; + echo "
画像を保存
"; + } } - $image->scaleImage($maxW, $maxH, true); - $out = imagickToBlob($image, $format); - } - - $base64 = base64_encode($out['data']); - $mime = $out['mime']; - echo "

変換結果:

"; - echo "

"; - echo "画像を保存"; - } -} -?> + ?> +
+
+