2016-11-24 7 views
0

이전 Symfony 2.3 프로젝트를 얻었습니다. 전에 Symfony를 사용하지 않았습니다 (Angularjs에 있음). 그래서 조금 어렵습니다.symfony 2.3 + liip + gaufrette = 원격 이미지의 엄지 손가락 만들기 (URL로)

내가하고 싶은 일 : 로컬 이미지 또는 원격 이미지의 엄지 손가락을 표시 할 수 있도록 프로젝트를 조정해야합니다 (이미 업로드 된 이미지의 전체 URL을 가져옵니다). 엄지 손가락은 로컬 캐시에 만들어야합니다.

이미 필터가있는 프로젝트에서 사용되는 이미지 묶음. KnpGaufretteBundle을 작곡가와 함께 설치했습니다.

1.in services.yml

services: 
    acme.liip_imagine.binary.loader.stream.profile_photos: 
     class: "%liip_imagine.binary.loader.stream.class%" 
     arguments: 
      - 'gaufrette://profile_photos/' 
     tags: 
      - { name: 'liip_imagine.binary.loader', loader: 'stream.profile_photos' } 

2.in config.yml

view.twig

// If i display directly the img it works 
{% set img = row.path %} 
<a href="{{ img }}" class="grouped_elements" rel="group" title="{{ row.copyright }}"> 
    <img src="{{ img }}" width="100px" alt="{{ img }}" border="0" /> 
</a> 

// but i get an error with this : 
{% set imgspe = row.path|basename %} 
{% set img = ['uploads/'~module.uploaddir~'/', imgspe]|join('') %} 
<a href="{{ asset(img) }}" class="grouped_elements" rel="group" title="{{ row.copyright }}"> 
    <img src="{{ asset(img) | imagine_filter('url_thumb') }}" alt="{{ imgspe }}" border="0" /> 
</a> 

liip_imagine: 
    #cache_clearer: false 
    #cache_mkdir_mode: 0777 
    loaders: 
     stream.profile_photos: 
      stream: 
       wrapper: gaufrette://profile_photos 
    filter_sets: 
     url_thumb: 
      data_loader: stream.profile_photos 
      filters: 
       thumbnail: { size: [100, 100], mode: outbound } 

3.in 오류 :

NetworkError: 404 Not Found - http://publish.test/app_dev.php/media/cache/url_thumb/http://www.jump-voyage.com/wp-content/uploads/2016/06/Google-Images-4.jpg 

'Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "Source image not found." at /var/www/test/publishv2/vendor/liip/imagine-bundle/Liip/ImagineBundle/Binary/Loader/StreamLoader.php line 55' 
01,

로컬 경로 + URL 경로 연결이므로 URL이 좋지 않습니다.

어떻게해야합니까?

답변

0

나는 liip/gaufrette없이 수동으로 처리합니다.

내가 수동으로 수행

<?php 
/* 
* étapes 
* 
* si image existe 
*  on la retourne 
* 
* sinon 
*  créer le chemin complet 
*  créer la vignette 
*  retourner la vignette 
* 
* chemin ou sont stocké les images : media/cache_url_thumb/thumb_{{w}}_{{h}} 
* 
*/ 

// retourne le contenu d'une image 
function sendimg($path,$filename){ 
    $contents = file_get_contents($path.$filename); 
    header('Content-type: image/jpeg'); 
    echo $contents; 
} 

/** 
* crée une miniature dans le dossier $updir 
* @param $updir : dossier ou crée la miniature 
* @param $img  : image orignale 
* @param $finalimg : image finale 
* @param $width 
* @param $height 
*/ 
function makeThumbnails($updir, $img, $finalimg,$width=134, $height=189) 
{ 
    $thumbnail_width = $width; 
    $thumbnail_height = $height; 
    $arr_image_details = getimagesize("$updir" . "$img"); 
    // cl($arr_image_details); 
    $original_width = $arr_image_details[0]; 
    $original_height = $arr_image_details[1]; 
    if ($original_width > $original_height) { 
     $new_width = $thumbnail_width; 
     $new_height = intval($original_height * $new_width/$original_width); 
    } else { 
     $new_height = $thumbnail_height; 
     $new_width = intval($original_width * $new_height/$original_height); 
    } 
    $dest_x = intval(($thumbnail_width - $new_width)/2); 
    $dest_y = intval(($thumbnail_height - $new_height)/2); 
    if ($arr_image_details[2] == IMAGETYPE_GIF) { 
     $imgt = "ImageGIF"; 
     $imgcreatefrom = "ImageCreateFromGIF"; 
    } 
    if ($arr_image_details[2] == IMAGETYPE_JPEG) { 
     $imgt = "ImageJPEG"; 
     $imgcreatefrom = "ImageCreateFromJPEG"; 
    } 
    if ($arr_image_details[2] == IMAGETYPE_PNG) { 
     $imgt = "ImagePNG"; 
     $imgcreatefrom = "ImageCreateFromPNG"; 
    } 
    if ($imgt) { 
     $old_image = $imgcreatefrom("$updir" . "$img"); 
     $new_image = imagecreatetruecolor($thumbnail_width, $thumbnail_height); 
     imagecopyresized($new_image, $old_image, $dest_x, $dest_y, 0, 0, $new_width, $new_height, $original_width, $original_height); 
     $imgt($new_image, "$updir" . $finalimg); 
    } 
} 

//crypte le nom pour éviter les erreurs avec caractères bizarre dans nom fichiers 
function toMd5($string){ 
    return md5($string); 
} 


// créer un dossier si il n'éxiste pas 
function createDir($path){ 
    if (!is_dir($path)) { 
     if (!mkdir("$path", 0777,true)) { 
      die('Echec lors de la création du repertoire $path pour les thumb images distantes...'); 
     } 
    } 
} 


$originalSrc = $_GET["src"]; 
$filename = toMd5($originalSrc); 
$path = 'media/cache_url_thumb/'."thumb_".$_GET["width"]."_".$_GET["height"]."/"; 
$path .= substr($filename,0,3) . "/"; 

// vérifier si image existe 
if(file_exists($path.$filename)){ 
    sendimg($path,$filename); 
}else{ 
    // l'image n'existe pas 
    createDir($path); 
    $tmpfilename = 'original_'.$filename; 
    copy($originalSrc , $path.$tmpfilename); 
    makeThumbnails($path ,$tmpfilename,$filename,$_GET["width"],$_GET["height"]); 
    unlink($path.$tmpfilename); 
    sendimg($path,$filename); 
} 
?> 

과 나뭇 가지 :

<a href="{{ img }}" class="grouped_elements" rel="group" title="{{ row.copyright }}"> 
    <img src="/geturlimage.php?src={{ img |url_encode }}&width=100&height=100" alt="{{ img }}" border="0" /> 
</a>