PDF 파일에서 JPG 이미지를 만들기 위해 "Imagick"이라는 PHP 확장자를 사용하려고합니다.
는 내가 일이 확장을 필요로 두 가지 상황이 있습니다 Contao 3.5.14Contag 3.5 및 Imagick php 확장자
사용
나는 뉴스 기사에 PDF 파일을 첨부 할 때 첫 번째 상황입니다.
이 경우, 사용자 지정 템플릿을 할당하는 사용자 지정 News List 모듈을 만듭니다.
이 사용자 지정 템플릿에서 JPG를 저장하기 위해 일부 PHP를 던졌습니다.
그것은 잘 작동 않습니다
<div class="publication layout_full block<?= $this->class ?>">
<h2><?= $this->headline ?></h2>
<?php if ($this->hasMetaFields): ?>
<p class="info"><?php echo $this->parseDate("F Y", strtotime($this->date)); ?><?= $this->author ?> <?= $this->commentCount ?></p>
<?php endif; ?>
<?php if ($this->hasSubHeadline): ?>
<h4><?= $this->subHeadline ?></h4>
<?php endif; ?>
<?php if ($this->addImage): ?>
<div class='image_container'>
<img src='<?= $this->singleSRC ?>'/>
</div>
<?php endif; ?>
<?php if ($this->enclosure): ?>
<div class="enclosure">
<?php for($i=0;$i<count($this->enclosure);$i++) {
// the IMAGICK bit:
$pdf_file = $this->enclosure[$i]['enclosure'].'[0]';
$save_to = 'files/thumbnails/'.$this->enclosure[$i]['link'].'.jpg';
if (!file_exists($save_to)) {
$im = new Imagick($pdf_file);
$im->setImageFormat ("jpeg");
$im->writeImage ($save_to);
}
?>
<div class="vignette"><a target="_blank" href="<?= $this->enclosure[$i]['enclosure'] ?>" title="<?= $this->enclosure[$i]['title'] ?> (<?= $this->enclosure[$i]['filesize'] ?>)"><img src='<?= $save_to ?>'/></a></div>
<?php } ?>
</div>
<?php endif; ?>
// and so on...
</div>
을 지금 여기 나 두통주는 두 번째 상황이 온다 ...
을 나는 '내용 요소를 다운로드 "를 사용하는 동안 PDF 파일에서 JPG를 만들 Imagick 확장을 사용할 필요가 .
Fatal error: Uncaught exception ImagickException with message unable to open image `files/Folder/myFile.pdf': No such file or directory @ error/blob.c/OpenBlob/2589 thrown in templates/ce_download.html5 on line 11
#0 templates/ce_download.html5(11): Imagick->__construct('files/Folder...')
#1 system/modules/core/library/Contao/BaseTemplate.php(88): include('/home/www/clien...')
#2 system/modules/core/library/Contao/Template.php(277): Contao\BaseTemplate->parse()
#3 system/modules/core/classes/FrontendTemplate.php(46): Contao\Template->parse()
#4 system/modules/core/elements/ContentElement.php(289): Contao\FrontendTemplate->parse()
#5 system/modules/core/elements/ContentDownload.php(72): Contao\ContentElement->generate()
#6 system/modules/core/library/Contao/Controller.php(484): Contao\ContentDownload->generate()
#7 system/cache/dca/tl_content.php(1166): Contao\Controller::getContentElement(Object(Contao\ContentModel))
#8 system/modules/core/drivers/DC_Table.php(4321): tl_content->addCteType(Array)
#9 system/modules/core/drivers/DC_Table.php(378): Contao\DC_Table->parentView()
#10 system/modules/core/classes/Backend.php(650): Contao\DC_Table->showAll()
#11 system/modules/core/controllers/BackendMain.php(131): Contao\Backend->getBackendModule('article')
#12 contao/main.php(20): Contao\BackendMain->run()
#13 {main}
: 내 다운로드 요소를 배치 위치를 기사로 이동하려고 할 때
<?php $this->extend('block_searchable'); ?>
<?php $this->block('content'); ?>
<!--------Here's the IMAGICK bit------------->
<?php
$pdf_file = $this->singleSRC.'[0]';
$save_to = 'files/thumbnails/'.$this->id.'.jpg';
if (!file_exists($save_to)) {
$im = new Imagick($pdf_file);
$im->setImageFormat ("jpeg");
$im->writeImage ($save_to);
}
?>
<!--------Here's end the IMAGICK bit------------>
<a href="<?= $this->href ?>" title="<?= $this->title ?>">
<div class="image_container">
<img style="width:100%;height:auto" src='<?= $save_to ?>' />
</div>
</a>
<div class="teaser">
<a href="<?= $this->href ?>" title="<?= $this->title ?>">
<h2> <?= $this->link ?> </h2>
</a>
</div>
<?php $this->endblock(); ?>
그리고 치명적인 오류 다시 사무실에 던져 :
나는 나의 Imagick 비트를 추가하기 위해 ce_download.html5 템플릿을 수정
ce_download.html5의 11 번째 줄은 입니다. $ im = new Imagick ($ pdf_file);
처음에는 경로와 관련된 문제라고 생각했지만 JPG가 올바르게 만들어져 프런트 엔드에 잘 표시되기 때문이 아닙니다. 그래서 ce_ templates가 작동하는 방식과 백 오피스에 표시되는 방식과 관련이 있어야합니다.
저는이 PHP 코드를 ce_download 템플릿을 사용하지 않고 작동시키는 법을 정말로 모릅니다.
나는 저를 도울 수있는 누구에게나 감사 할 것입니다.
감사
비니
'새로운 Imagick를보십시오 (.. TL_ROOT '/'$의 pdf_file) Waouh @fritzmg' – fritzmg
! 그것은 지금 작동하지 않습니다 ... 그래서 그것은 경로 문제가있었습니다 :// 답변으로 귀하의 의견을 자유롭게 변경, 그래서 나는 라이트 대답으로 선택할 수 있습니다. 대단히 감사합니다... – Vinny