PHP WordをHTML出力 docx_reader

GitHubのリンク

< コード例 >

docx_reader.phpを配置してincludeで読み込んで使います。


include('./docx_reader.php');


// == リクエストパラメータ == //
$filename = $_POST["filename"] ? $_POST["filename"] : $_GET["filename"];

if (!$filename) {
  $filename = "/path/filename.docx";
}

$doc = new Docx_reader();
$doc->setFile($filename);

if(!$doc->get_errors()) {
    $html = $doc->to_html();
    $plain_text = $doc->to_plain_text();

    echo $html;
} else {
    echo implode(', ',$doc->get_errors());
}
echo "\n";

PHP ExcelをHTML出力 excel2html

GitHubのリンク

< インストール >

composer でインストールします。

[????@????]# composer require tomk79/php-excel2html
Cannot load Zend OPcache - it was already loaded
No composer.json in current directory, do you want to use the one at /home/ApacheDoc/invfiles? [Y,n]? n
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? y
Info from https://repo.packagist.org: #StandWithUkraine
./composer.json has been created
Running composer update tomk79/php-excel2html
Loading composer repositories with package information
Updating dependencies
Lock file operations: 14 installs, 0 updates, 0 removals
  - Locking ezyang/htmlpurifier (v4.16.0)
  - Locking maennchen/zipstream-php (2.1.0)
  - Locking markbaker/complex (3.0.2)
  - Locking markbaker/matrix (3.0.1)
  - Locking michelf/php-markdown (1.9.1)
  - Locking myclabs/php-enum (1.8.4)
  - Locking phpoffice/phpspreadsheet (1.25.2)
  - Locking psr/http-client (1.0.2)
  - Locking psr/http-factory (1.0.2)
  - Locking psr/http-message (1.1)
  - Locking psr/simple-cache (1.0.1)
  - Locking symfony/polyfill-mbstring (v1.27.0)
  - Locking tomk79/filesystem (1.2.3)
  - Locking tomk79/php-excel2html (0.1.2)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 14 installs, 0 updates, 0 removals
  - Installing ezyang/htmlpurifier (v4.16.0): Extracting archive
  - Installing symfony/polyfill-mbstring (v1.27.0): Extracting archive
  - Installing psr/http-message (1.1): Extracting archive
  - Installing myclabs/php-enum (1.8.4): Extracting archive
  - Installing maennchen/zipstream-php (2.1.0): Extracting archive
  - Installing markbaker/complex (3.0.2): Extracting archive
  - Installing markbaker/matrix (3.0.1): Extracting archive
  - Installing psr/http-client (1.0.2): Extracting archive
  - Installing psr/http-factory (1.0.2): Extracting archive
  - Installing psr/simple-cache (1.0.1): Extracting archive
  - Installing tomk79/filesystem (1.2.3): Extracting archive
  - Installing phpoffice/phpspreadsheet (1.25.2): Extracting archive
  - Installing michelf/php-markdown (1.9.1): Extracting archive
  - Installing tomk79/php-excel2html (0.1.2): Extracting archive
5 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating autoload files
3 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found

< コード例 >

<?php

require_once( '../vendor/autoload.php' );

ini_set("memory_limit", "-1");
ini_set('max_execution_time', 180);

// == リクエストパラメータ == //
$filename = $_POST["filename"] ? $_POST["filename"] : $_GET["filename"];

if (!$filename) {
  $filename = "/path/filename.xlsx";
}

$src = (new \tomk79\excel2html\main($filename))->get_html(
        array(
            'renderer' => 'strict',
            'cell_renderer' => 'html',
            'render_cell_width' => true,
            'render_cell_background' => true,
            'render_cell_borders' => true,
            'render_cell_align' => true,
            'render_cell_vertical_align' => true,
        ));

print $src;

< 画面例 >

GCP Translation API RESTでPHPから使う

< コード例 >


<?php

/*
  Google Translationリクエスト用スクリプト
  ソース言語は英語に固定
  
 */

include '../DefaultHeaderIni.php';
include '../MySQLConnectConfig_aviation.php';

// ============= Const =============== //

$URL = "https://www.googleapis.com/language/translate/v2?key=";
$KEY = "??????????????????????????????????";


// =================================== //

// == リクエストパラメータ取得 == //
$q = $_POST["q"] ? $_POST["q"] : $_GET["q"];
$target = $_POST["target"] ? $_POST["target"] : $_GET["target"];

if (!$q) {
  $q = "Good Morning";
}
if (!$target) {
  $target = "in";
}


// 送信データ //
// リテラルは必ずはシングルクオテーションにする //
$postdata = array(
    'q' => $q,
    'source' => 'en',
    'target' => $target
);

$postdata_json = json_encode($postdata);
$postdata_json = str_replace("\r", "", $postdata_json);
//exit;

$url = $URL.$KEY;

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => $postdata_json,
    CURLOPT_HTTPHEADER => [
          'Content-Type: application/json; charset=UTF-8',
          "accept: application/json"
      ],
    
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
}
else {
  echo $response;
}

< リクエストForm data >

q: U A881 United Airlines B789 N17963 Landed 
from ORD to HND  Last Direction 269 Runway 22 Squawk 3126
21Seconds ago
target: ja

< レスポンス例 >

{
  "data": {
    "translations": [
      {
        "translatedText": "U A881 ユナイテッド航空 B789 N17963 ORD から HND に着陸 最後の方向 269 滑走路 22 スコーク 3126 21 秒前"
      }
    ]
  }
}

PHP PDO MySQLの検索結果のキャスト

PHP PDO MySQLでセレクトした数値結果から判別するプログラムで、=== で厳密型チェックしてる場合、MySQLがTINYINTのフィールドを読み込む際、環境によって(Windows or Linux, PHP7 or PHP8)はうまく読み込めなくなったのでキャストしてみると解決しました。

< コード例 >

SQL

$SQL = <<<EOM
SELECT IS_MAILHTML
FROM m_user_aviation
WHERE 
  ID = :USERID     
EOM;

これはだめ

// パラメータセット //
  $stmt = $dbh->prepare($SQL);
  $stmt->bindvalue(':USERID', $userid, PDO::PARAM_STR);
  $stmt->execute();


  // 格納 //
  //$array = array();
  $mailtype= "";
  while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
   //var_dump ($row["IS_MAILHTML"]) ;
   $mailtype = $row["IS_MAILHTML"] === 1 ? "html" : "text";  
  }

これでオーケー

// パラメータセット //
  $stmt = $dbh->prepare($SQL);
  $stmt->bindvalue(':USERID', $userid, PDO::PARAM_STR);
  $stmt->execute();


  // 格納 //
  //$array = array();
  $mailtype= "";
  while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
   //var_dump ($row["IS_MAILHTML"]) ;
   $mailtype = (int)$row["IS_MAILHTML"] === 1 ? "html" : "text";   // 必ずintにキャスト
  }

Windows10 で PHP8.1のcurlが動かないエラーの解消

Windows10でXAMPでインストールしたPHP8.1でCurlがどうしても動かないので、調べて何とか動くようになりました。

ここで教えていただきました。

調べると沢山ヒットしたので試したところ、
php.iniのextensionの設定、dllのコピー等、
どれもだめだったところ、環境変数のPathにPHPのパスを記述することで解決してます。

< phpinfoで確認 >

< 環境変数 path >

[商品価格に関しましては、リンクが作成された時点と現時点で情報が変更されている場合がございます。]

独習PHP 第4版 [ 山田 祥寛 ]
価格:3740円(税込、送料無料) (2023/1/18時点)

PHP GD 画像切り抜き

< コード例 >


<?php

/**
 * GD 画像 切り抜き
 * argv : 1:元ファイル名, 2:生成ファイル名, 3: 左上X座標, 4: 左上Y座標, 5:幅, 6:高さ  
 */
 
// 引数取得 //
$srcfnm = $argv[1];
$newfnm = $argv[2];
$sx = $argv[3];
$sy = $argv[4];
$w = $argv[5];
$h = $argv[6];

// 元画像サイズ取得 //
list($src_width, $src_height, $type) = getimagesize($srcfnm);

// 対象イメージ格納 //
switch ($type) {
  case IMAGETYPE_JPEG:    // 2
    $srcimg = imagecreatefromjpeg($srcfnm);
    break;
  case IMAGETYPE_PNG:     // 3
    $srcimg = imagecreatefrompng($srcfnm);
    break;
  case IMAGETYPE_GIF:     // 1
    $srcimg = imagecreatefromgif($srcfnm);
    break;
}

// 矩形指定
$rect = array();
$rect['x'] = $sx;
$rect['y'] = $sy;
$rect['width'] = $w;
$rect['height'] = $h;

// 画像を切り抜き
//$im_in = $func_create($srcfnm);
$im_out = imagecrop($srcimg, $rect);

// 結果ファイルに出力 //
$filepath = pathinfo($newfnm);
$ext = mb_strtolower($filepath['extension']);
$res = 1;
try {
  if ($ext === "jpg" || $ext === "jpeg") {
    imagejpeg($im_out, $newfnm, 100);
  }
  else if ($ext === "png") {
    imagepng($im_out, $newfnm, 9);
  }
  else if ($ext === "gif") {
    imagegif($im_out, $newfnm, 100);
  }
}
catch (Exception $ex) {
  $res = 0;
}

// 解放 //
imagedestroy($srcimg);
imagedestroy($im_out);

// 連想配列に格納 //
$responce = [];
$responce["Result"] = $res;

// JSONに変換して結果出力 //
echo json_encode($responce);


?>


[商品価格に関しましては、リンクが作成された時点と現時点で情報が変更されている場合がございます。]

独習PHP 第4版 [ 山田 祥寛 ]
価格:3740円(税込、送料無料) (2022/12/26時点)

PHP GD 画像ファイル合成

[ コード例 ]


<?php

/**
 * GD 合成位置指定画像ファイル合成 
 * argv : 1:ファイル名A(背景), 2:ファイル名B(パネル), 3:生成ファイル名, 
 *        4:合成位置 (N, NE, E, SE, S, SW, W, NW, C), 5:パッディング (オプション) 
 */

// 引数取得 //
$fnm_a = $argv[1];
$fnm_b = $argv[2];
$fnm_new = $argv[3];
$mrglocation = $argv[4];
$PADDING = isset($argv[5]) ? $argv[5] : 12;   // 指定がない場合は12ピクセル

// Linux 引数の" が認識されてない対策 //
$fnm_a = str_replace("^", " ", $fnm_a);
$fnm_b = str_replace("^", " ", $fnm_b);
$fnm_new = str_replace("^", " ", $fnm_new);

// A, B画像サイズ, 画像タイプ取得 //
list($a_width, $a_height, $type_a) = getimagesize($fnm_a);
list($b_width, $b_height, $type_b) = getimagesize($fnm_b);

// 対象イメージ格納 //
switch ($type_a) {
  case IMAGETYPE_JPEG:    // 2
    $image_a = imagecreatefromjpeg($fnm_a);
    break;
  case IMAGETYPE_PNG:     // 3
    $image_a = imagecreatefrompng($fnm_a);
    break;
  case IMAGETYPE_GIF:     // 1
    $image_a = imagecreatefromgif($fnm_a);
    break;
}
switch ($type_b) {
  case IMAGETYPE_JPEG:    // 2
    $image_b = imagecreatefromjpeg($fnm_b);
    break;
  case IMAGETYPE_PNG:     // 3
    $image_b = imagecreatefrompng($fnm_b);
    break;
  case IMAGETYPE_GIF:     // 1
    $image_b = imagecreatefromgif($fnm_b);
    break;
}

// コピー先の画像,コピー元の画像,コピー先のx座標,コピー先のy座標,コピー元のx座標,コピー元のy座標,コピー元の幅,コピー元の高さ //
// 合成する //
switch ($mrglocation) {
  case "NW":   // 左上
    imagecopy($image_a, $image_b, $PADDING, $PADDING, 0, 0, $b_width, $b_height);
    break;
  case "NE":   // 右上
    imagecopy($image_a, $image_b, $a_width - $b_width - $PADDING, $PADDING, 0, 0, $b_width, $b_height);
    break;
  case "SE":   // 右下
    imagecopy($image_a, $image_b, $a_width - $b_width - $PADDING, $a_height - $b_height - $PADDING, 0, 0, $b_width, $b_height);
    break;
  case "SW":   // 左下
    imagecopy($image_a, $image_b, 12, $a_height - $b_height - $PADDING, 0, 0, $b_width, $b_height);
    break;

  case "N":    // 上中央
    imagecopy($image_a, $image_b, $a_width / 2 - $b_width / 2, $PADDING, 0, 0, $b_width, $b_height);
    break;
  case "S":    // 下中央
    imagecopy($image_a, $image_b, $a_width / 2 - $b_width / 2, $a_height - $b_height - $PADDING, 0, 0, $b_width, $b_height);
    break;
  case "E":    // 右中央
    imagecopy($image_a, $image_b, $a_width - $b_width - $PADDING, $a_height / 2 - $PADDING / 2, 0, 0, $b_width, $b_height);
    break;
  case "W":    // 左中央
    imagecopy($image_a, $image_b, $PADDING, $a_height / 2 - $PADDING / 2, 0, 0, $b_width, $b_height);
    break;
  case "C":    // 中央中央
    imagecopy($image_a, $image_b, $a_width / 2 - $b_width / 2, $a_height / 2 - $b_height / 2, 0, 0, $b_width, $b_height);
    break;
  }


// 結果ファイルに出力 //
$filepath = pathinfo($fnm_new);
$ext = mb_strtolower($filepath['extension']);
$res = 1;
try {
  if ($ext === "jpg" || $ext === "jpeg") {
    imagejpeg($image_a, $fnm_new, 100);
  }
  else if ($ext === "png") {
    imagepng($image_a, $fnm_new, 9);
  }
  else if ($ext === "gif") {
    imagegif($$image_a, $fnm_new, 100);
  }
}
catch (Exception $ex) {
  $res = 0;
}

// 解放 //
imagedestroy($image_a);
imagedestroy($image_b);

// 連想配列に格納 //
$responce = [];
$responce["Result"] = $res;

// JSONに変換して結果出力 //
//echo json_encode($responce, JSON_PRETTY_PRINT);
echo json_encode($responce);

?>


[ 利用例 ]

Aファイル (背景)

Bファイル (パネル)

合成結果 NE パディング指定あり

合成結果 SE

合成結果 SW

合成結果 NW

合成結果 S

PHP GD 画像連結合成

ここで教えて頂きました : http://thr3a.hatenablog.com/entry/20181108/1541682523

[ コード例 ]


<?php

/**
 * GD 画像 連結位置方角指定連結合成
 * argv : 1:ファイル名A, 2:ファイル名B, 3:生成ファイル名, 4:追加位置 (NESW) 
 */

// 引数取得 //
$fnm_a = $argv[1];
$fnm_b = $argv[2];
$fnm_new = $argv[3];
$mrglocation = $argv[4];

// A, B画像サイズ取得 //
list($a_width, $a_height, $type_a) = getimagesize($fnm_a);
list($b_width, $b_height, $type_b) = getimagesize($fnm_b);

//echo $a_width . ":" . $a_height . "\n";
//echo $b_width . ":" . $b_height . "\n";

// 連結位置別新画像サイズ //
$total_width = 0;
$total_height = 0;
switch ($mrglocation) {
  case 'N':
    $total_height = $a_height + $b_height;
    $total_width = $a_width > $b_width ? $a_width : $b_width;
    break;
  case 'E':
    $total_width = $a_width + $b_width;
    $total_height = $a_height > $b_height ? $a_height : $b_height;
    break;
  case 'S':
    $total_height = $a_height + $b_height;
    $total_width = $a_width > $b_width ? $a_width : $b_width;
    break;
  case 'W':
    $total_width = $a_width + $b_width;
    $total_height = $a_height > $b_height ? $a_height : $b_height;
    break;
}
echo $total_width . ":" . $total_height . "\n";

// 連結サイズのキャンバス生成 //
$result_im = imagecreatetruecolor($total_width, $total_height);
// 背景を白にする //
$result_bgcol = ImageColorAllocate($result_im, 255, 255, 255);
imagefilledrectangle($result_im, 0, 0, $total_width, $total_height, $result_bgcol);

// 対象イメージ格納 //
$image_a = imagecreatefromjpeg($fnm_a);
$image_b = imagecreatefromjpeg($fnm_b);


// コピー先の画像,コピー元の画像,コピー先のx座標,コピー先のy座標,コピー元のx座標,コピー元のy座標,コピー元の幅,コピー元の高さ
//imagecopy($result_im, $image_a, 0, 0, 0, 0, $a_width, $a_height);
//
// 連結する //
switch ($mrglocation) {
  case "S":
    imagecopy($result_im, $image_a, 0, 0, 0, 0, $a_width, $a_height);
    imagecopy($result_im, $image_b, 0, $a_height, 0, 0, $b_width, $b_height);
    break;
  case "N":
    imagecopy($result_im, $image_a, 0, $b_height, 0, 0, $a_width, $a_height);
    imagecopy($result_im, $image_b, 0, 0, 0, 0, $b_width, $b_height);
    break;
  case "E":
    imagecopy($result_im, $image_a, 0, 0, 0, 0, $a_width, $a_height);
    imagecopy($result_im, $image_b, $a_width, 0, 0, 0, $b_width, $b_height);
    break;
  case "W":
    imagecopy($result_im, $image_a, $b_width, 0, 0, 0, $a_width, $a_height);
    imagecopy($result_im, $image_b, 0, 0, 0, 0, $b_width, $b_height);
    break;
}

// 新ファイルに出力 //
$filepath = pathinfo($fnm_new);
$ext = mb_strtolower($filepath['extension']);
$res = 1;
try {
  if ($ext === "jpg" || $ext === "jpeg") {
    imagejpeg($result_im, $fnm_new, 100);
  }
  else if ($ext === "png") {
    imagepng($result_im, $fnm_new, 9);
  }
  else if ($ext === "gif") {
    imagegif($result_im, $fnm_new, 100);
  }
}
catch (Exception $ex) {
  $res = 0;
}

// 解放 //
imagedestroy($result_im);

// 連想配列に格納 //
$responce = [];
$responce["Result"] = $res;
$responce["TotalW"] = $total_width;
$responce["TotalH"] = $total_height;

// JSONに変換して結果出力 //
//echo json_encode($responce, JSON_PRETTY_PRINT);
echo json_encode($responce);

?>


[ 利用画像サンプル ]

A画像

B画像

[ 連結結果 ]

大きい方の画像の余白は白にしています。大きい方の画像を先にストレッチしておくと、余白をなくせるかと思います。

S連結

W連結

PHP GD 枠付文字パネルファイル生成機

[ コード例 ]


<?php

/**
 * GD 文字列パネル描画ファイル生成
 * argv : 1: 生成ファイル名,  2: 横サイズ 3: 縦サイズ 4: フォント色 5:背景色 6:枠色
 *        7: 枠サイズ
 *        8: 書込文字列 9: 文字サイズ 10 : 背景透明度 (0 - 127) (8-10 オプション)
 */

// == 引数取得 == //
$fnm = $argv[1];
$xsz = $argv[2];
$ysz = $argv[3];

// 色指定 //
$rgb_font = $argv[4];
$rgb_fill = $argv[5];
$rgb_frame = $argv[6];
//  isset($argv[10]) ? $argv[10] : "";

// 枠サイズ //
$frlen = $argv[7]; 

// 文字 //
$text = isset($argv[8]) ? $argv[8] : "";
$textsz = isset($argv[9]) ? $argv[9] : "";
$alpha = isset($argv[10]) ? $argv[10] : 0;

// Linux 引数の" が認識されてない対策 //
$text = str_replace("_", " ", $text);

// 引数を16進文字列に分解して配列に入れる //
$fontcols = explode(":", $rgb_font);
$fillcols = explode(":", $rgb_fill);
$framecols = explode(":", $rgb_frame);

// +++ 色文字列を数値に変換 +++ //
// ImageColorAllocate用に10進配列にする //
$fontdecs = [];
foreach ($fontcols as $col) {
  $fontdecs[] = hexdec($col);
}
$filldecs = [];
foreach ($fillcols as $col) {
  $filldecs[] = hexdec($col);
}
$framedecs = [];
foreach ($framecols as $col) {
  $framedecs[] = hexdec($col);
}


// 画像の新規生成 //
$img = imagecreate($xsz, $ysz);

# 色を作る #
// 文字 //
$imcol_font = ImageColorAllocate($img, $fontdecs[0], $fontdecs[1], $fontdecs[2]);
// 背景は透明度指定あり //
$imcol_fill = ImageColorAllocateAlpha($img, $filldecs[0], $filldecs[1], $filldecs[2], $alpha);
// 枠 //
$imcol_frame = ImageColorAllocate($img, $framedecs[0], $framedecs[1], $framedecs[2]);

# UTF8へ変換 #
$text = mb_convert_encoding($text, 'UTF-8', 'auto');

// フォント //
if (DIRECTORY_SEPARATOR == "/") {
  $font = "/usr/share/fonts/vlgothic/VL-Gothic-Regular.ttf";
}
else {
  $font = "C:\Windows\Fonts\msgothic.ttc";
}

// 背景を描画する //
/* img, x1, y1, x2, y2, color */
imagefilledrectangle($img, 0, 0, $xsz, $ysz, $imcol_fill);

// 枠線幅 //
imagesetthickness($img, $frlen);

// 文字を書き込む //
/* img, テキストサイズ, アングル, X, Y, color, font, text */
$textx = (int)($frlen) + (int)($textsz / 2);
$texty = (int)($frlen + $textsz) + (int)($textsz / 2);
ImageTTFText($img, $textsz, 0, $textx, $texty, $imcol_font, $font, $text);

// 枠を引く //
/* img, x1, y1, x2, y2, color */
imagerectangle($img, 0, 0, $xsz, $ysz, $imcol_frame);

// ファイルに出力 //
$filepath = pathinfo($fnm);
$ext = mb_strtolower($filepath['extension']);
$res = 1;
try {
  if ($ext === "jpg" || $ext === "jpeg") {
    imagejpeg($img, $fnm, 100);
  }
  else if ($ext === "png") {
    imagepng($img, $fnm, 9);
  }
  else if ($ext === "gif") {
    imagegif($img, $fnm, 100);
  }
}
catch (Exception $ex) {
  $res = 0;
}

// 解放 //
imagedestroy($img);

// 連想配列に格納 //
$responce = [];
$responce["Result"] = $res;

// JSONに変換して出力 //
//echo json_encode($responce, JSON_PRETTY_PRINT);
echo json_encode($responce);

?>


[ 生成例 ]

      

PHP GD スケッチ風変換

[ コード例 ]

IMG_FILTER_MEAN_REMOVAL 以外の引数はありません。


<?php

/**
 * GD 画像風景画変換
 * argv : 1 : ソースファイル名, 2 : デストファイル名
 */
 
// 引数取得 //
$srcfnm = $argv[1];
$dstfnm = $argv[2];

// 画像タイプ取得 //
list($src_width, $src_height, $type) = getimagesize($srcfnm);

switch ($type) {
  case IMAGETYPE_JPEG:    // 2
    $im = imagecreatefromjpeg($srcfnm);
    break;
  case IMAGETYPE_PNG:     // 3
    $im = imagecreatefrompng($srcfnm);
    break;
  case IMAGETYPE_GIF:     // 1
    $im = imagecreatefromgif($srcfnm);
    break;
}

// 変換して保存 //
$res = 1;
if ($im) {
  imagefilter($im, IMG_FILTER_MEAN_REMOVAL);
}
else {
  $res = 0;
}

if ($type == IMAGETYPE_JPEG) {
  imagejpeg($im, $dstfnm);
}
else if ($type == IMAGETYPE_PNG) {
  imagepng($im, $dstfnm);
}
else {
  imagegif($im, $dstfnm);
}

// 解放 //
gedestroy($im);

// 連想配列に格納 //
$responce = [];
$responce["Result"] = $res;

// JSONに変換して出力 //
echo json_encode($responce, JSON_PRETTY_PRINT);
?>


ここで教えていただきました。http://kyasper.com/php-tips/

[ 利用例・変換前 ]

[ 利用例・変換後 ]