SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ImageMagick and Ghostscript work but I still can't convert pdf to jpg

    Installed ImageMagick and GhostScript with macPorts. Both installs pass the "working" tests listed on there respective sites. When I try a conversion nothing happens.

    convert.php
    Code:
    <?php
    //$pdf = "/images/image.pdf";
    //$pdfimage = pdf_open_image_file($pdf, "jpeg", "test.jpg");
    //pdf_place_image($pdf, $pdfimage, 10, 10, 0.6);
    
    exec("convert images/image.pdf images/image.jpeg")
    
    ?>
    
    <html>
    <head>
    <title>pdf to jpg converter</title>
    </head>
    <?php
    echo "<img src='images/image.jpg'>";
    ?>
    <body>
    </body>
    </html>
    Am I missing something?

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,411
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    You could try looking on the ImageMagick forum; there are 30 pages of pdf problems !
    This one may be of help ? http://redux.imagemagick.org/discour...8898&hilit=pdf

  3. #3
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's one universal answer to all exec() problems: always append 2>&1 to your command line and see what error message the shell returns.

  4. #4
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get an "unexpected T_LNUMBER" when running that.

    Code:
    exec ("convert images/image.pdf images/image.jpg") 2>&1;

  5. #5
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    exec("convert images/image.pdf images/image.jpg 2>&1"$out) ;
    echo 
    "<pre>";
    print_r($out); 

  6. #6
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help!!

    I got this:
    Code:
     dyld: Library not loaded: /usr/X11R6/lib/libdpstk.1.dylib
    Referenced from: /usr/local/bin/convert
    I then copied libdpstk.1.0.dylib (couldn't find libdpstk.1.dylib) to /usr/X11R6/lib and renamed it the libdpstk.1.dylib

    then got this:
    Code:
    /usr/X11R6/lib/libdpstk.1.dylib: mmap() error 22 at address=0x8AA16000, size=0x00001824 in Segment::map() mapping /usr/X11R6/lib/libdpstk.1.dylib

  7. #7
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm... looks like imagick attempts to invoke XWindows, what it shouldn't. Try calling ghostscript binary directly, with a command line like this (test this from the command prompt first)

    Code:
    gs -q -sDEVICE=jpeg -dBATCH -dNOPAUSE -dFirstPage=1 -dLastPage=1 -sOutputFile=output.jpg input.pdf 2>&1

  8. #8
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it returns
    Code:
    -dvar=name requires name-null, true, or false

  9. #9
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry i typed in the command wrong

    it works from the command line and in a perl script
    but i still can't get it run in php


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •