FPDF + Images + Remote Location

Discussion in 'PHP' started by ip076, Jun 10, 2006.

  1. #1
    Hey All,

    I'm using the FPDF class to dynamically create PDF files with PHP. So far so good, its a really decent setup, and I'd recommend it to anyone looking to create PDFs.

    I'm trying to add images. The images I'm trying to add are remotely located on a different site (They are National Weather Service Weather Charts, I'm creating a site for Pilot's to get Weather Briefings).

    The images are also gifs, which I have modifed FPDF to handle Gifs. My problem comes from the fact they are remote.

    If someone could take a few minutes and let me know which grouping of php functions I can use to grab the remote image and save it onto my server, it would be greatly appreciated. I'm sure once I get the image locally, I can add it to the PDF.

    I'm pretty decent with PHP, but I actually havent used many of the file manipulation functions and therefor am fairly lost on how to do the above task.

    Thanks!
     
    ip076, Jun 10, 2006 IP
  2. captsulu32

    captsulu32 Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Looking for the same answers.
    I am working on a website for a travel agency and they want to be able to deliver a Map and directions along with all there trip information inside the pdf. I have been using fpdf for about 3 years on this same website.

    Let me know if you find a solution.

    Thanks!
     
    captsulu32, Feb 1, 2008 IP
  3. sharqi

    sharqi Guest

    Messages:
    105
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Taken from www.php.net/gd

    function by office at 4point-webdesign dot com


    imgcomp is the quality, i turned it around so now its from 0 -best to 100 -most compressed.
    
    For gif version just change the functions names.
    
    function resampimagejpg($forcedwidth, $forcedheight, $sourcefile, $destfile, $imgcomp)
        {
        $g_imgcomp=100-$imgcomp;
        $g_srcfile=$sourcefile;
        $g_dstfile=$destfile;
        $g_fw=$forcedwidth;
        $g_fh=$forcedheight;
    
        if(file_exists($g_srcfile))
            {
            $g_is=getimagesize($g_srcfile);
            if(($g_is[0]-$g_fw)>=($g_is[1]-$g_fh))
                {
                $g_iw=$g_fw;
                $g_ih=($g_fw/$g_is[0])*$g_is[1];
                }
                else
                {
                $g_ih=$g_fh;
                $g_iw=($g_ih/$g_is[1])*$g_is[0];   
                }
            $img_src=imagecreatefromjpeg($g_srcfile);
            $img_dst=imagecreate($g_iw,$g_ih);
            imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_is[0], $g_is[1]);
            imagejpeg($img_dst, $g_dstfile, $g_imgcomp);
            imagedestroy($img_dst);
            return true;
            }
            else
            return false;
        }
    PHP:
     
    sharqi, Feb 1, 2008 IP