2013-02-19 4 views
-2

먼저 폴더의 파일 이름을 확인한 다음 URL을 생성하는 코드를 사용하고 있습니다. url에서 이미지 파일이있는 특수 행을 찾으십시오. 이미지와 주소를 올바르게 표시하지만 이미지가 너무 크면 오랜 시간이 걸립니다. 축소판을 만들어 이미지 대신 표시 할 수 있습니까? 고맙습니다!PHP URL에서 가져온 이미지의 축소판

require_once('simple_html_dom.php'); 
$files = scandir('files/'); 
foreach($files as $file) { 
    if($file == '.' || $file == '..') continue; 
    $file = basename($file, ".html"); 
    $url = 'http://address.com/test/'.$file; 
    $html = file_get_html($url); 
foreach($html->find('img') as $element) { 
    if (strpos($element,'address.com') !== false) { 
    $url = $element->src; 
    echo $url.'</br>'; 
    echo '<IMG SRC="',$url, '" WIDTH="128" HEIGHT="96" BORDER="0" ALT="" /><br/>'; 
    } 
    } 
} 

답변

0

당신은 여전히 ​​오래 걸릴 시간을 실제 이미지 크기를 decress하지 않는 CSS를 clip:rect(50px 218px 155px 82px);

설정 폭과 높이를 사용하므로로드 할. 이 기사는 단계 div 작성 및 css 코딩 단계를 참조하십시오.

보조 노트로 또한 http://www.seifi.org/css/creating-thumbnails-using-the-css-clip-property.html

, 아무것도 실제로 TUMBNAILS을하지 이겼어! 사이드 썸네일 생성기가 제공되지만 실제로 미리보기 이미지를 만들면 얻을 수있는 최상의 결과입니다.

0

블로그 게시물을 How to proportionally resize uploaded images에 작성 했으므로 코드를 the sample I wrote에서 원하는대로 수행 할 수 있어야합니다.

앞으로 내 사이트가 죽을 경우를 대비하여 아래 코드를 붙여 넣으십시오.

<?php 

// *snip* Removed form stuff 
$image = imagecreatefromjpeg($pathToImage); 


// Target dimensions 
$max_width = 240; 
$max_height = 180; 


// Calculate new dimensions 
$old_width  = imagesx($image); 
$old_height  = imagesy($image); 
$scale   = min($max_width/$old_width, $max_height/$old_height); 
$new_width  = ceil($scale*$old_width); 
$new_height  = ceil($scale*$old_height); 


// Create new empty image 
$new = imagecreatetruecolor($new_width, $new_height); 


// Resample old into new 
imagecopyresampled($new, $image, 
     0, 0, 0, 0, 
     $new_width, $new_height, $old_width, $old_height); 


// Catch the image data 
ob_start(); 
imagejpeg($new, NULL, 90); 
$data = ob_get_clean(); 


// Destroy resources 
imagedestroy($image); 
imagedestroy($new); 


// Output image data 
header("Content-type: image/jpeg", true, 200); 
echo $data; 

아마도이 기능을 스틱으로 출력하여 파일로 변경할 수 있습니다. 그런 다음 foreach 루프에서 축소판을 생성하고 원본 대신 축소판에 연결하십시오. 이미지의 미리보기 이미지를 이미 만들었는지 확인하여 각 이미지에 대해 두 번 이상 수행하지 않아야합니다.

관련 문제