开发者

PHP Safari PDF to Image Problem

I am trying to use headers and Imagick to display PDFs as an image. I have it working in other browsers except in Safari the image comes with a black background. An example is here and the code the generated the example is below:

http://www.iptlock.com/pdf_test.php

<?php
header("Pragma: no-cache");
header("Expires: -1");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

$file_location='/media/files/bFdIdcxsOKtkBjzayEBD.pdf';

$im =开发者_StackOverflow社区 new imagick($file_location."[0]");
$im->setImageFormat( "jpg" );
header( "Content-Type: image/jpeg" );
echo $im;
?>

So I am not sure what is wrong or how to rectify the problem.


It occurs the same to me when I make thumbnails from PDF to JPG/JPEG.

This is the function I've implemented to do so:

function writeAttachmentsToDisk($mbox,$uid,$part,$dir,$subtype,$subject,$attachments,$readonly=false,$dataInici=''){
  if(!file_exists($dir)){
    mkdir($dir);
  }
  if(!empty($dataInici)){
    $subject = trim(str_replace($dataInici,'',$subject));
  }
  $filename = setNomArxiu(@iconv_mime_decode($subject,0,'UTF-8').(count($attachments)>0?'-'.strtoupper(alpha(count($attachments))):'')).'.'.$subtype;
  if(!$readonly || !file_exists($dir.'/'.$filename)){
      $temp_filename = 'tmp.eml';
      $email_file = $dir."/".$temp_filename;
      @imap_savebody($mbox,$email_file,$uid,$part,FT_UID | FT_PEEK);
      if(file_exists($email_file)){
          $tb = false;
          for($a=0;$a<count($attachments);$a++){
            if(files_identical($email_file,$attachments[$a])){
                $tb = true;
                break;
            }
          }
          if(!$tb){
              $command = "php -r '\$fh = fopen(\$argv[1], \"r\"); \$theData=fread(\$fh, filesize(\$argv[1])); fclose(\$fh); echo base64_decode(\$theData);' '$email_file' > $dir/$filename";
              exec($command,$output,$result);
              if($result!=0){
                unlink($email_file);
                @rmdir($dir);
                return false;
              } else {
                unlink($email_file);
                return $dir.'/'.$filename;
              }
          }else{
            unlink($email_file);
            @rmdir($dir);
            return false;
          }
      }else{
        unlink($email_file);
        @rmdir($dir);
        return false;
      }
  }else{
    return $dir.'/'.$filename;
  }
}

The function above uses other functions which are irrelevant to the question at hand (alpha, setNomArxiu, files_identical).

I guess the problem must be somehow here:

$command = "php -r '\$fh = fopen(\$argv[1], \"r\"); \$theData=fread(\$fh, filesize(\$argv[1])); fclose(\$fh); echo base64_decode(\$theData);' '$email_file' > $dir/$filename";
exec($command,$output,$result);

The resulting image can be seen here in most browsers but appears darkened, nearly black, in Safari and when saved in Mac.

Any ideas on what's going on here?

Thanks!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜