2017-02-24 2 views
-1

크기를 사용하여 PHP로 이미지를자를 필요가 있습니다.PHP로 크기가없는 이미지를 자르려면?

그리고 JPEG 형식으로 로컬에 저장하십시오. 나는이받을

치수,

{"left":82.5,"top":48.875,"width":660,"height":371.25} 

나는 이미지의 원본 크기로 잘라해야합니다.

Ex. 이미지 크기가 1200x800이면 실제 크기의 결과 이미지 크기이며 크기 조정 또는 일부가 아닙니다. 품질이 동일해야하기 때문에.

이미지를 자르기 위해 어떻게이 매개 변수를 사용할 수 있습니까?

가능합니까?

$image = realpath("/path/to/your/image.extension"); 
$cropped = realpath("/path/to/your/output/image.png"); 

$imObj = new Imagick(); 
$imObj->cropImage($width, $height, $offset_x, $offset_y); 
$imObj->setImageFormat("png"); // this is unnesesary, you can force an image format with the extension of the output filename. 
$imObj->writeImage($cropped); 

무손실 출력에 관해서는, 무손실 인코딩 이미지 포맷을 사용

+0

해당 값은 어떤 차원입니까? 0.5 px는 생성하기가 어렵습니다 – Martin

답변

0

는 내장 imagick class 사용. PNG는 네트워크 전송 ("Adam-7"인터레이스)을 위해 설계 되었기 때문에 작업에 적합합니다. 확인 그래픽 디자인 스택에 무손실 이미지 형식에 대한이 관련 질문 :

What are lossless image formats?

+1

Imagick은 *** 내장되지 않습니다 ***이»PECL 확장은 PHP와 번들되지 않습니다. ' – Martin

0

당신은 꽤 많이 정확히 이것에 대한 설계되었습니다 imageCopyResampled 기능을 사용할 수 있습니다.

$image = imagecreatefromjpeg($imageFileURL); 
/*** 
* resize values (imported) 
***/ 
$left = 82; 
$top = 49; 
$width = 660; 
$height = 371; 

/*** 
* Create destination image 
***/ 
$newImage = imagecreatetruecolor($width,$height); 
$saveToFile = "destintion filespace of image file.jpg" 

if(imagecopyresampled($newImage, $image, //dest/source images 
     0, 0,       // dest coordinates 
    $left, $top,       // source coordinates 
    $width, $height,      // size of area to paste to 
    $width, $height      // size of area to copy from 
)){ 
    imagejpeg($newImage,$saveToFile,100); //zero compression saved to file 
    print "image resized ok!!"; 
} 

새로운 fileimage는 $width, $height 지정된 크기되며 $left$top에 주어진 값에 의해 원래의 화상으로부터 오프셋된다. 귀하의 질문에서 이것은 당신이 원하는 것처럼 보입니다. 이렇게하면 파일의 크기가 조정되거나 이미지의 압축이 변경되지 않습니다 (파일을 저장하고 직접 이러한 세부 정보를 설정할 때까지).

관련 문제