다른 이미지 인 템플릿에도 이미지를 추가하려고합니다. PHP codeigniter를 사용하고 있습니다. 두 파일 모두 .PNG 파일 일 때이 목적을 위해 잘 작동하는 코드 스 니펫이 있습니다.다른 이미지에 이미지 추가
<?php
function attachIcon($imgname)
{
$mark = imagecreatefrompng($imgname);
imagesavealpha($mark, true);
list($icon_width, $icon_height) = getimagesize($imgname);
$img = imagecreatefrompng('images/sprites/navIcons.png');
imagesavealpha($img, true);
$move_left = 10;
$move_up = 9;
list($mainpic_width, $mainpic_height) = getimagesize('images/sprites/navIcons.png');
imagecopy($img, $mark, $mainpic_width-$icon_width-$move_left, $mainpic_height-$icon_height-$move_up, 0, 0, $icon_width, $icon_height);
imagepng($img); // display the image + positioned icon in the browser
//imagepng($img,'newnavIcon.png'); // rewrite the image with icon attached.
}
header('Content-Type: image/png');
attachIcon('icon.png');
?>
그러나 템플릿 '이미지/스프라이트/navIcons.png'는 PNG 파일이고 다른 이미지가 다른 유형의 경우 내 때라도 코드가 작동하지 않습니다 (.JPG 말할 수) : 내 코드는 다음과 같습니다 :
<?php
function attachIcon($imgname)
{
$mark = imagecreatefrompng($imgname);
imagesavealpha($mark, true);
list($icon_width, $icon_height) = getimagesize($imgname);
$img = imagecreatefrompng('images/sprites/navIcons.png');
imagesavealpha($img, true);
$move_left = 10;
$move_up = 9;
list($mainpic_width, $mainpic_height) = getimagesize('images/sprites/navIcons.png');
imagecopy($img, $mark, $mainpic_width-$icon_width-$move_left, $mainpic_height-$icon_height-$move_up, 0, 0, $icon_width, $icon_height);
imagepng($img); // display the image + positioned icon in the browser
//imagepng($img,'newnavIcon.png'); // rewrite the image with icon attached.
}
header('Content-Type: image/jpg');
attachIcon('icon.jpg');
?>
-Am 난 아무것도 실종? - 파일 확장자로 작업해야합니까? - 템플릿을 .PNG 파일로 만들 수 있고 다른 이미지를 다른 형식으로 만들 수 있습니다 (.JPG). 내가 뭔가를 바꿀 필요가 있습니다.
도움을 주시면 감사하겠습니다.
추신 : 나는이 포럼에서 아주 오래된 게시물의 코드를 얻었습니다. 그러나 나는 그것이 꽤 나이가 들었고 아무도 그것을 점검하지 않는다고 생각했다. 그래서 나는 새로운 질문에 나의 질문을한다! 감사합니다
감사 sinni800는
나는 의견 당신에 댓글을 올리려면했는데,하지만 난 내 코드를 추가 할 때부터 응답 여기에 새 메시지를 추가했다.
"imagecreatefromjpeg"를 사용하는 다음 코드도 시도해 보았습니다. 내 코드 :
<?php
function attachIcon($imgname) {
$mark = imagecreatefromjpeg($imgname);
imagesavealpha($mark, true);
list($icon_width, $icon_height) = getimagesize($imgname);
$img = imagecreatefrompng(base_url() . '/uploaded_images/output/viewer.png');
imagesavealpha($img, true);
$move_left = 280;
$move_up = 450;
list($mainpic_width, $mainpic_height) = getimagesize(base_url() . '/uploaded_images/output/viewer.png');
imagecopy($img, $mark, $mainpic_width - $icon_width - $move_left, $mainpic_height - $icon_height - $move_up, 0, 0, $icon_width, $icon_height);
imagepng($img); // display the image + positioned icon in the browser
//imagepng($img,'newnavIcon.png'); // rewrite the image with icon attached.
}
header('Content-Type: image/jpeg');
attachIcon(base_url().'/uploaded_images/output/koala.jpg');
?>
아직 작동하지 않습니다.