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

From: Date: Tue, 23 Jul 2002 01:16:06 +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-14830@lists.php.net to get a copy of this message
ID: 18459 Updated by: sniper@php.net Reported By: sramage@fatpipeinternet.com -Status: Open +Status: Feedback Bug Type: PDF related Operating System: FreeBSD PHP Version: 4.2.1 New Comment: Please provide a SHORT script...and by short we mean under 10 lines.. Previous Comments: ------------------------------------------------------------------------ [2002-07-21 17:02:00] sramage@fatpipeinternet.com self contained code below here is link to a standard tiff file http://fatpipeinternet.com/test/before1.tif <?php @define ("DOCUMENT_TIFF", "tiff"); 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)) { 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"); $count=1; while($image=pdf_open_image_file($pdf,DOCUMENT_TIFF,$input_file,"page",$count)){ if($count>2){ break; } $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_save($pdf); $data=pdf_get_buffer($pdf); pdf_close($pdf); pdf_delete($pdf); $fp=fopen($output_file,"w"); fwrite($fp,$data,strlen($data)); fclose($fp); $return=$output_file; }else{ $return=false; } }else{ $return=false; } } $passs_or_fail=""; if(is_array($_FILES)){ while(list($k,$file_array)=each($_FILES)){ if(file_exists($file_array["tmp"])){ if(TiffToPDF($file_array["tmp"],"tiff_to_pdf_test.pdf")){ $pass_or_fail="PASSED<iframe width=\"500\" height=\"200\" src=\"tiff_to_pdf_test.pdf\"></iframe>"; }else{ $pass_or_fail="couldn't Convert TIFF to PDF"; } }else{ $pass_or_fail="File didn't upload"; } } } $output="$pass_or_fail<BR><form enctype=\"multipart/form-data\" action=\"\" method=\"post\">Send this file: <input name=\"userfile\" type=\"file\"><input type=\"submit\" value=\"Send File\"></form>"; echo $output; ?> ------------------------------------------------------------------------ [2002-07-21 14:04:27] derick@php.net Then provide a short selfcontained script that reproduces the problem so that we can try it. Derick ------------------------------------------------------------------------ [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; } } ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/18459 -- Edit this bug report at http://bugs.php.net/?id=18459&edit=1

« previous php.bugs (#14830) next »