Bug #18459: Crashes When using pdf_open_image_file() with a tiff
| From: | sramage at fatpipeinternet dot com | Date: | Sun, 21 Jul 2002 17:22:34 +0000 |
| Subject: | Bug #18459: Crashes When using pdf_open_image_file() with a tiff | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-14740@lists.php.net to get a copy of this message | ||
From: sramage@fatpipeinternet.com
Operating system: FreeBSD
PHP version: 4.2.1
PHP Bug Type: PDF related
Bug description: Crashes When using pdf_open_image_file() with a tiff
Stats
Apache 1.3.22
PDFlib GmbH Version 4.0.2 Revision 1.106
Here's the first tested piece of code, works with Both JPEG and PNG, but
hangs with TIFF.
<?php
@define ("DOCUMENT_PNG", "png");
@define ("DOCUMENT_JPEG", "jpeg");
@define ("DOCUMENT_GIF", "gif");
@define ("DOCUMENT_PDF", "pdf");
@define ("DOCUMENT_TIFF", "tiff");
function
CreateScaledPDF($input_file,$file_type=DOCUMENT_PDF,$width=421,$height=595,$output_image=false){
if(!$height){
$height=84;
}
if(!$width){
$width=59;
}
if(file_exists($input_file)){
if(!$output_file){
$ext=strrev(strtok(strrev($input_file),"."));
$core=strrev(strtok(""));
$output_file=$core."_thumb.pdf";
}
$pdf = pdf_new();
if (pdf_open_file($pdf)) {
pdf_begin_page($pdf,$width,$height);
switch($file_type){
case DOCUMENT_PDF:
$pdi=pdf_open_pdi ($pdf,$input_file,"",0);
$page=pdf_open_pdi_page($pdf,$pdi,1,"Thumbnail");
$x=pdf_get_pdi_value($pdf,"pagewidth",$pdi,$page,0);
$y=pdf_get_pdi_value($pdf,"pageheight",$pdi,$page,0);
break;
case DOCUMENT_TIFF:
$image=pdf_open_image_file($pdf,$file_type,$input_file,"page",1);
$x=pdf_get_value($pdf,"imagewidth",$image);
$y=pdf_get_value($pdf,"imageheight",$image);
break;
case DOCUMENT_JPEG:
case DOCUMENT_PNG:
$image=pdf_open_image_file($pdf,$file_type,$input_file);
$x=pdf_get_image_width($pdf,$image);
$y=pdf_get_image_height($pdf,$image);
break;
}
if(!$y){
$y=1;
}
if(!$x){
$x=1;
}
$scalex=$width/$x;
$scaley=$height/$y;
$scale=min($scalex,$scaley);
if($scale>1){
$x=$width-($x/2);
$y=$height-($y/2);
$scale=1;
}else{
if($y*$scale == $height && $x*$scale != $width){
$y=0;
$x=($width-($x*$scale))/2;
}elseif($x*$scale == $width && $y*$scale != $height){
$x=0;
$y=($height-($y*$scale))/2;
}else{
$x=0;
$y=0;
}
}
switch($file_type){
case DOCUMENT_PDF:
pdf_place_pdi_page($pdf,$page,$x,$y,$scale,$scale);
pdf_close_pdi_page($pdf,$page);
pdf_close_pdi($pdf,$pdi);
break;
case DOCUMENT_TIFF:
case DOCUMENT_JPEG:
case DOCUMENT_PNG:
pdf_place_image($pdf,$image,$x,$y,$scale);
pdf_close_image($pdf,$image);
break;
}
pdf_end_page($pdf);
pdf_close($pdf);
$pdf_output=pdf_get_buffer($pdf);
$fp=fopen($output_file,"w");
fwrite($fp,$pdf_output,strlen($pdf_output));
fclose($fp);
pdf_delete($pdf);
$return=true;
}else{
$this->error="couldn't create PDF file";
$return=false;
}
}else{
$this->error="no input file";
$return=false;
}
return $return;
}
?>
--
Edit bug report at http://bugs.php.net/?id=18459&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=18459&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=18459&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=18459&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=18459&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=18459&r=support
Expected behavior: http://bugs.php.net/fix.php?id=18459&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=18459&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=18459&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=18459&r=globals