Bug #18459 Updated: Crashes When using pdf_open_image_file() with a tiff

From: Date: Sun, 21 Jul 2002 18:03:52 +0000
Subject: Bug #18459 Updated: Crashes When using pdf_open_image_file() with a tiff
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-14745@lists.php.net to get a copy of this message
ID: 18459 Updated by: derick@php.net Reported By: sramage@fatpipeinternet.com Status: Open Bug Type: PDF related Operating System: FreeBSD PHP Version: 4.2.1 Previous Comments: ------------------------------------------------------------------------ [2002-07-21 13:54:06] sramage@fatpipeinternet.com I'm at a shared hosting facility without shell access, is there any other way to get the needed info? all I get access to is my HTTP access and error logs. ------------------------------------------------------------------------ [2002-07-21 13:40:52] derick@php.net Thank you for this bug report. To properly diagnose the problem, we need a backtrace to see what is happening behind the scenes. To find out how to generate a backtrace, please read http://bugs.php.net/bugs-generating-backtrace.php Once you have generated a backtrace, please submit it to this bug report and change the status back to "Open". Thank you for helping us make PHP better. ------------------------------------------------------------------------ [2002-07-21 13:26:24] sramage@fatpipeinternet.com Here's one piece of code that I couldn't test but its better for iteration testing and more compact: function TIFFtoPDF($input_file,$output_file=false){ if(file_exists($input_file)){ if(!$output_file){ $ext=strrev(strtok(strrev($input_file),".")); $core=strrev(strtok("")); $output_file=$core.".pdf"; } $pdf = pdf_new(); if (pdf_open_file($pdf,$output_file)) { pdf_set_parameter($pdf, "warning", "true"); pdf_set_info($pdf, "Creator", "Automatic"); pdf_set_info($pdf, "Author", "Automatic"); pdf_set_info($pdf, "Title", basename($input_file)); pdf_set_info($pdf, "Subject", "Generated PDF Document Thumbnail"); $count=1; while($image=@pdf_open_image_file($pdf,DOCUMENT_TIFF,$input_file,"page",$count)){ $x=pdf_get_value($pdf,"imagewidth",$image); $y=pdf_get_value($pdf,"imageheight",$image); pdf_begin_page($pdf,$x,$y); pdf_place_image($pdf,$image,0,0,1); pdf_close_image($pdf,$image); pdf_end_page($pdf); $count++; } pdf_close($pdf); $return=$output_file; }else{ $return=false; } }else{ $return=false; } } ------------------------------------------------------------------------ [2002-07-21 13:22:33] sramage@fatpipeinternet.com 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 this bug report at http://bugs.php.net/?id=18459&edit=1

« previous php.bugs (#14745) next »