'1219', 'quantity' => intval($item['col38'])],
['length' => '2438', 'quantity' => intval($item['col39'])],
['length' => '3000', 'quantity' => intval($item['col40'])],
['length' => '3500', 'quantity' => intval($item['col41'])],
['length' => '4000', 'quantity' => intval($item['col42'])],
['length' => '4150', 'quantity' => intval($item['col43'])]
];
// 동일한 `size` 값이 이미 존재하는지 확인
$existingKey = array_search($boxSize, array_column($box_data, 'size'));
if ($existingKey === false) {
// 새로운 사이즈 추가
$box_data[] = [
'size' => $boxSize,
'sum' => 1,
'cover' => $cover,
'fincover' => $fincover,
'boxdirection' => $boxdirection,
'boxfrontbottom' => $boxfrontbottom,
'boxrailwidth' => $boxrailwidth,
'length_data' => array_map(function ($length) {
return ['length' => $length['length'], 'sum' => $length['quantity']];
}, $boxLengths)
];
} else {
// 기존 데이터에 값 누적
$box_data[$existingKey]['sum'] += 1;
$box_data[$existingKey]['cover'] += $cover;
$box_data[$existingKey]['fincover'] += $fincover;
// 길이 데이터 누적
foreach ($boxLengths as $index => $length) {
$box_data[$existingKey]['length_data'][$index]['sum'] += $length['quantity'];
}
}
}
function fetchImageData($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // HTTPS 인증 무시
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // 연결 시간 초과 설정
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // 리다이렉트 따라가기
$imageData = curl_exec($ch);
// if (curl_errno($ch)) {
// echo "DEBUG: cURL 오류 -> " . curl_error($ch) . "
";
// }
curl_close($ch);
return $imageData;
}
function drawImage($sourcePath, $savePath, $textData, $fontSize = 3) {
// URL을 로컬 경로로 변환
$documentRoot = $_SERVER['DOCUMENT_ROOT'];
global $root_dir;
$relativePath = str_replace($root_dir, '', $savePath);
$localSavePath = $documentRoot . $relativePath;
// echo "DEBUG: 변환된 로컬 저장 경로 -> {$localSavePath}
";
// 폴더 생성
$saveDir = dirname($localSavePath);
if (!is_dir($saveDir)) {
if (!mkdir($saveDir, 0777, true)) {
echo "DEBUG: 폴더 생성 실패 -> {$saveDir}
";
return false;
}
} else {
chmod($saveDir, 0777);
// echo "DEBUG: 폴더 권한 설정 -> {$saveDir}
";
}
// 원본 이미지 데이터 가져오기 (cURL 사용)
// echo "DEBUG: 원본 이미지 경로 -> {$sourcePath}
";
$imageData = fetchImageData($sourcePath);
if (!$imageData) {
// echo "DEBUG: 원본 이미지 데이터를 가져올 수 없습니다.
";
return false;
}
// echo "DEBUG: 원본 이미지 데이터 로드 성공
";
// 이미지 로드 및 작업
$tempImage = tempnam(sys_get_temp_dir(), 'image');
file_put_contents($tempImage, $imageData);
$image = @imagecreatefromjpeg($tempImage);
unlink($tempImage);
if (!$image) {
echo "DEBUG: JPEG 이미지를 로드할 수 없습니다.
";
return false;
}
// echo "DEBUG: 이미지 리소스 생성 성공
";
// 텍스트 추가
$textColor = imagecolorallocate($image, 255, 0, 0); // 빨간색
foreach ($textData as $textItem) {
if (isset($textItem['text'], $textItem['x'], $textItem['y'])) {
imagestring(
$image,
$fontSize,
intval($textItem['x']),
intval($textItem['y']),
$textItem['text'],
$textColor
);
// echo "DEBUG: 텍스트 추가 -> '{$textItem['text']}' @ ({$textItem['x']}, {$textItem['y']})
";
}
}
// 이미지 저장
$result = @imagejpeg($image, $localSavePath);
// if ($result) {
// echo "DEBUG: 이미지 저장 성공 -> {$localSavePath}
";
// } else {
// echo "DEBUG: 이미지 저장 실패 -> {$localSavePath}
";
// }
imagedestroy($image);
return $result ? $localSavePath : false;
}
?>
';
// print_r($box);
// echo '';
?>
| 셔터박스 (점검구:=$box['boxdirection']?>) |
|---|
|
①전면부 ②린텔부 ③하부점검구 ④후면코너부 ⑤후면점검구 ⑥상부덮개 ⑦측면부(마구리) |