발 완료 후 메모용도로 작성한 글임.

자세한 내용은 알지 못함으로 질문은 받지 않는 글임.



#convert 사용하기 위해서 일단 설치


[root@localhost ~]# yum install ImageMagick


convert 를 이용해서 파일 변환


#convert 옵션( 출처 : http://openwiki.kr/tech/imagemagick ) 시작


파일포맷변경

convert image_org.gif image_out.jpg 

[설명] image_org.gif 이미지를 image_out.jpg로 바꾼다.


convert image_org.png image_out.jpg 

[설명] image_org.png 이미지를 image_out.jpg로 바꾼다.



확대,축소,리사이즈

convert image_org.jpg -resize 25%x25% -quality 100 image_out.jpg

[설명] image_org.jpg 이미지를 1/4 축소한 image_out.jpg로 바꾼다.


convert image_org.jpg -resize 800x600 -quality 100 image_out.jpg 

[설명] image_org.jpg 이미지를 800x600픽셀로 리사이즈 하지만 비율을 유지하며 큰사이즈 비율 기준으로 image_out.jpg를 생성한다.


convert image_org.jpg -resize 800x600\! -quality 100 image_out.jpg 

[설명] image_org.jpg 이미지를 800x600픽셀로 강제적으로 바꾸어 image_out.jpg를 생성한다.



[설명] "-quality 100"이란 옵션을 주면 품질을 최대한 좋게한다.



회전

convert image_org.png -matte -background none -rotate 90 image_out.png 

[설명] 이미지를 90도 회전하고 나머지 영역은 투명하게한다.


convert image_org.png -matte -background none -rotate -15 image_out.png 

[설명] 이미지를 -15도 회전하고 나머지 영역은 투명하게한다.



좌우반전,상하반전

convert -flop image_org.jpg image_out.jpg 

[설명] image_org.jpg 이미지를 좌우반전시켜 image_out.jpg 이미지를 생성한다.


convert -flip image_org.jpg image_out.jpg 

[설명] image_org.jpg 이미지를 상하반전시켜 image_out.jpg 이미지를 생성한다.



흑백,갈색 효과

convert image_org.jpg -colorspace gray image_out.jpg 

[설명] image_org.jpg 이미지를 흑백효과를 적용하고 image_out.jpg 이미지를 생성한다.


convert image_org.jpg -sepia-tone 80% image_out.jpg 

[설명] image_org.jpg 이미지를 갈색효과를 적용하고 image_out.jpg 이미지를 생성한다.



밝게,어둡게

convert image_org.jpg -sigmoidal-contrast 3,0% image_out.jpg

[설명] image_org.jpg 이미지를 밝게하여 image_out.jpg 이미지를 생성한다.


convert image_org.jpg -sigmoidal-contrast 3,100% image_out.jpg 

[설명] image_org.jpg 이미지를 어둡게하여 image_out.jpg 이미지를 생성한다.



자르기(crop)

convert image_org.jpg -crop 800x600+10+20 image_out.jpg 

[설명] image_org.jpg를 Left 10픽셀 Top 20픽셀 부터 800x600픽셀까지 자르고 그 결과로 image_out.jpg 이미지를 생성한다.


convert image_org.jpg -crop 800x600+10-30 image_out.jpg 

[설명] image_org.jpg를 Left 10픽셀 Top -30픽셀 부터 800x600픽셀까지 자르고 그 결과로 image_out.jpg 이미지를 생성한다.



캔버스생성

convert -size 800x600 xc:white image_out.jpg 

[설명] 800x600픽셀인 흰색 image_out.jpg 이미지를 생성한다.


convert -size 800x600 xc:skyblue image_out.gif 

[설명] 800x600픽셀인 하늘색 image_out.jpg 이미지를 생성한다.


convert -size 800x600 xc:none image_out.png 

[설명] 800x600픽셀인 투명 image_out.png 이미지를 생성한다.



글자이미지생성

convert -background white -fill black -font batang.ttf -pointsize 36 label:"Test\n한글" image_out.png 

[설명] "Test\n한글"이란 글자로 image_out.png 이미지를 생성한다. (이미지배경은 흰색, 글자색은 검정색, 폰트는 바탕, 폰트사이즈는 36pt)



이미지합성

composite -dissolve 60 -geometry +50+100 image_temp.png image_org.jpg image_out.jpg 

[설명] image_temp.png 이미지를 투명도 60%로 하여 image_org.jpg의 50,100 픽셀 좌표에 올려 합성후 image_out.jpg 이미지를 생성한다.


#convert 옵션( 출처 : http://openwiki.kr/tech/imagemagick ) 끝



#php 를 이용한 convert 실행 샘플

--> pdf 파일은 png 파일로 변환

--> include 나 path 의 경우 절대경로로 적었음

--> 해당 파일을 ~/convert.php 로 저장했음

--> 실행은 콘솔창에서 php '~/convert.php'; 로 실행했음.

--> db에 저장된 파일중 pdf 파일만 선택하여 변환함.


<?php

$debug = true;

include_once('/var/www/html/common.php');


$bo_table = 'vfxx';


$directory = '/var/www/html/data/file/'.$bo_table;


$input_path = '/var/www/html/data/file/'.$bo_table;  //원본 파일 경로

$output_path = '/var/www/html/data/file/'.$bo_table.'/output'; // 변환되어 저장될 파일의 경로


$inputPath = $input_path;

$outputPath = $output_path;



@mkdir($output_path, 0755);

@chmod($output_path, 0644);


$sdate = date('Ymd')-1;


$sql = "select * from mfile

where bo_table = '$bo_table'

and file_name like '%.pdf'

";


$result = mysql_query($sql);


while($row = mysql_fetch_assoc($result)){


$tmp_path = $outputPath.'/'.$row['file_idx'];


if(is_dir($tmp_path)){

shell_exec('rm -rf '.$tmp_path);

}

@mkdir($tmp_path, 0755);

@chmod($tmp_path, 0644);



$file_ext = '';

$file_name = '';

$file_ext = explode('.', $row['file_name ']);


for($i = 0; $i<count($file_ext) - 1;  $i++){

$file_name .= $file_ext[$i];

}


if(strtolower($file_ext[count($file_ext)-1]) == 'pdf'

&& !file_exists($tmp_path.'/'.$file_name.'0.png')

){

convertImg($directory.'/'.$row['file_name'], $tmp_path.'/'.$file_name.'.png');

}


}



function convertImg($ffilename, $tfilename){

$output = shell_exec('rm -rf /tmp/magick*');

$output = shell_exec('convert -size 2481x3508 xc:white -verbose -density 200 -trim '.$ffilename.' -quality 100 -sharpen 0x1.0 '.$tfilename);

// 2481x3508 사이즈로

// quality 100 --> 최대 품질

// density 200 --> 압축율은 적당히

// sharpen --> 이미지는 원본 수준으로



}


?>


#변환된 파일의 출력

--> output 디렉토리의 파일을 읽어 존재하는 모든 파일 출력



<div style="text-align:center; ">

    <div style="margin:auto;text-align:center; height:100%;overflow:hidden"><div>

<?php

      $bo_table = 'vfxx'

$dir = '/file/'.$bo_table.'/output/'.$file_idx;

$url = '/file/'.$bo_table.'/output/'.$file_idx;

$handler = opendir($dir); 


while ($filek[] = readdir($handler));

natsort($filek);


closedir($handler); 


foreach ($filek as $file){

if(stristr ( $file , 'png', false )){

echo '<div style="text-align:left; background-color:#fff;">';

echo "<img src='".$url.'/'.$file."' style='background-color:#fff;'/>";

echo '</div>';

}

}




?>

</div>

</div>


'프로그래밍 > PHP' 카테고리의 다른 글

PHP 서버에서 GCM 멀티캐스트 발송하는 방법  (0) 2014.12.05
by 차까꿍 2016. 7. 17. 09:11

PHP에서 GCM 멀티캐스트로 발송하는 방법은 정말 간단하게 구현할 수 있습니다.

GCM에서는 한번 발송에 1000개의 디바이스 토큰을 일괄 발송할 수 있는 멀티캐스트 기능이 포함되어 있어, 무척 편리해 졌는데요


100만건을 발송하더라도, 1000회만 커넥션을 맺으면 되므로 발송 속도가 무척이나 빠르겠죠..


우선, PHP에서 GCM발송 라이브러리를 작성합니다.

아래 라이브러리는 Github에서 가져왔습니다.  


GCMPushMessage.php


발송은 send 페이지에서 다음과 같이 작성합니다.


$devices는 Array변수로 디바이스 토큰값을 담아주면 됩니다. (최대 1000개)


만약, 등록건수가 1만건이다...  어떻게 1000으로 나눌수가 있을까요??


PHP에서는 아주 간단한 Array함수를 가지고 있더군요..


1만건을 $devices에 담아 array_chunk 함수로 나누면 되는거죠... 1000건씩...


array_chunk 함수는 아주 간편하게...나눠주니.. 계산할 필요없이 아주 편리하게 사용하면 됩니당@!!


http://php.net/manual/en/function.array-chunk.php


출처 : http://nonstop.pe.kr/php/1674

'프로그래밍 > PHP' 카테고리의 다른 글

PHP ImageMagick convert 를 이용한 이미지 변환  (0) 2016.07.17
by 차까꿍 2014. 12. 5. 09:05
| 1 |