0

을 필터링 한 후 내 데이터베이스에 이미지를 업로드 할 VichUploadBundle을 사용하고 나타나지 않고 LiipImage와 함께 웹 사이트에 표시되는 이미지의 썸네일을하고 싶습니다.LiipImagineBundle 그림

이 설정 파일 내 config.yml입니다

//..... 
vich_uploader: 
    db_driver: orm 
    twig: true 
    mappings: 
      product_image: 
       uri_prefix:   /images/products 
       upload_destination: '%kernel.root_dir%/../web/images/products' 

       inject_on_load:  false 
       delete_on_update: true 
       delete_on_remove: true 

liip_imagine: 

    # configure resolvers 
    resolvers: 

     # setup the default resolver 
     default: 

      # use the default web path 
      web_path: ~ 

    # your filter sets are defined here 
    filter_sets: 

     # use the default cache configuration 
     cache: ~ 
     # the name of the "filter set" 
     my_thumb: 

      # adjust the image quality to 75% 
      quality: 75 

      # list of transformations to apply (the "filters") 
      filters: 

       # create a thumbnail: set size to 120x90 and use the "outbound" mode 
       # to crop the image when the size ratio of the input differs 
       thumbnail: { size: [120, 90], mode: outbound } 

       # create a 2px black border: center the thumbnail on a black background 
       # 4px larger to create a 2px border around the final image 
       background: { size: [124, 98], position: center, color: '#000000' } 

liip에 대한 코드의 대부분은 똑바로 테스트를위한 문서에서 복사됩니다.

app: 
    resource: "@AppBundle/Controller/" 
    type:  annotation 

_liip_imagine: 
    resource: "@LiipImagineBundle/Resources/config/routing.xml 

마지막으로 내가 업로드 할 이미지 개체를 내 routing.yml입니다. 그것은뿐만 아니라 내가 이미지 테이블에 $ 그들과 배열에 넣어 가지고 내 컨트롤러에서 공식 Vich 문서

<?php 
namespace AppBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use Symfony\Component\HttpFoundation\File\File; 
use Vich\UploaderBundle\Mapping\Annotation as Vich; 

/** 
* @ORM\Entity 
* @Vich\Uploadable 
*/ 
class Image 
{ 
    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

    // ..... other fields 

    /** 
    * NOTE: This is not a mapped field of entity metadata, just a simple property. 
    * 
    * @Vich\UploadableField(mapping="product_image", fileNameProperty="imageName") 
    * 
    * @var File 
    */ 
    protected $imageFile; 

    /** 
    * @ORM\Column(type="string", length=255) 
    * 
    * @var string 
    */ 
    protected $imageName; 

    /** 
    * @ORM\Column(type="string", length=100) 
    * 
    * @var string 
    */ 
    protected $imageTitle = null; 

    /** 
    * @ORM\Column(type="string", length=100) 
    * 
    * @var string 
    */ 
    protected $imageAuthor = null; 

    /** 
    * If manually uploading a file (i.e. not using Symfony Form) ensure an instance 
    * of 'UploadedFile' is injected into this setter to trigger the update. If this 
    * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter 
    * must be able to accept an instance of 'File' as the bundle will inject one here 
    * during Doctrine hydration. 
    * 
    * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image 
    * 
    * @return Product 
    */ 
    public function setImageFile(File $image = null) 
    { 
     $this->imageFile = $image; 

     if ($image) { 
      // It is required that at least one field changes if you are using doctrine 
      // otherwise the event listeners won't be called and the file is lost 
      $this->updatedAt = new \DateTimeImmutable(); 
     } 

     return $this; 
    } 

    /** 
    * @return File|null 
    */ 
    public function getImageFile() 
    { 
     return $this->imageFile; 
    } 

    /** 
    * @param string $imageName 
    * 
    * @return Product 
    */ 
    public function setImageName($imageName) 
    { 
     $this->imageName = $imageName; 

     return $this; 
    } 

    /** 
    * @return string|null 
    */ 
    public function getImageName() 
    { 
     return $this->imageName; 
    } 

    /** 
    * @ORM\Column(type="datetime") 
    * 
    * @var \DateTime 
    */ 
    protected $updatedAt; 

    /** 
    * @return null 
    */ 
    public function getImageTitle() 
    { 
     return $this->imageTitle; 
    } 

    /** 
    * @param null $imageTitle 
    */ 
    public function setImageTitle($imageTitle) 
    { 
     $this->imageTitle = $imageTitle; 
    } 

    /** 
    * @return null 
    */ 
    public function getImageAuthor() 
    { 
     return $this->imageAuthor; 
    } 

    /** 
    * @param null $imageAuthor 
    */ 
    public function setImageAuthor($imageAuthor) 
    { 
     $this->imageAuthor = $imageAuthor; 
    } 
} 

에서 복사 한 코드입니다 나중에보기에 넣어

$em = $this->getDoctrine()->getManager(); 
$list = $em->getRepository(Image::class)->findAll(); 

및 그래서처럼 인쇄 (할 것) :

{% for l in list %} 
     <tr> 
      <td> 
       <img src="{{ asset('/images/products/'~l.imageName) | imagine_filter('my_thumb') }}" alt="{{ l.imageName }}"> 

      </td> 
      <td>{{ l.imageTitle }}</td> 
      <td>{{ l.imageAuthor }}</td> 
     </tr> 
    {% endfor %} 

을 불행하게도 출력은 다음과 같습니다,Website output


이제 경로가 정상입니다. 이미지 imagine_filter()없이 잘 작동합니다. Vich 에셋을 사용할 때도 같은 결과가 발생합니다. 이미지 아래에 링크 된 경로를 확인

은 다음과 같습니다

http://localhost:8000/media/cache/resolve/my_thumb/images/products/hqdefault.jpg

이미지의 경로는

웹/이미지/제품이다


문제가 무엇인지 아는 사람이 있습니까?

또는 모든 도움을

+0

로그를 확인하고 웹 서버 소유자 (또는 777 권한)와 함께 foder'/ web/media'를 만들려고 시도하십시오. – malcolm

답변

0

을 고정 놀라운 것

이미지 썸네일을 만들기위한 대안 번들 제공 : 나중에 삭제, GD파일 이름 php.ini 파일에서 및 재 작성 아파치 활성화를 cache fixed everything