Add watermark and resize image PHP script?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Goodings Media
    Confirmed User
    • Apr 2007
    • 1987

    #1

    Add watermark and resize image PHP script?

    Hiya,

    anyone know where i can get a simple (and free) PHP script that will

    Take the image that a user uplaods
    Add an alpha transparency watermark
    resize it to a fixed size

    and then pass it back to my script to insert it into the database

    Ive done a fair bit of googling on this but come up with nothing. I understand it'll need to use imagemagic.

    Thanks guys
    ICQ: 446-568-913 Email: liam||goodingsmedia.com msn: [email protected]
  • bonkerz2007
    Confirmed User
    • Sep 2005
    • 794

    #2
    http://www.phpscriptexpert.com/scrip...ermark&pid=198

    Comment

    • Goodings Media
      Confirmed User
      • Apr 2007
      • 1987

      #3
      hiya,

      i need the watermark to be permanent

      thanks
      ICQ: 446-568-913 Email: liam||goodingsmedia.com msn: [email protected]

      Comment

      • Goodings Media
        Confirmed User
        • Apr 2007
        • 1987

        #4
        bump for anyone who knows a bit of imagemagick
        ICQ: 446-568-913 Email: liam||goodingsmedia.com msn: [email protected]

        Comment

        • lb_vee
          Confirmed User
          • May 2004
          • 886

          #5
          Here's the docs for the imagemagick command line tools. If had a bit more time I'd actually get into the php api to see what they have.

          http://www.imagemagick.org/script/composite.php

          Im pretty sure you can also use the GD libs in php to get this done.

          Comment

          • ASACP Cal
            Registered User
            • Jun 2007
            • 6

            #6
            Standalone using php

            I was interested in this topic also.

            This code snippet will resize an image. (Remarkable what a pain in the ass such a basic operation is.) See below the example for combining images of different sizes or writing text directly to an image.

            If you want to save the image you can add a path to imagejpeg (see ca3.php.net/manual/en/function.getimagesize.php for another similar example).

            <?php
            $upload = $_FILES['img'];
            if ($upload['type'] != 'image/jpeg') die("only jpeg files are supported not {$upload['type']}!");
            $resize_pct = $_REQUEST['resize_pct'];
            if ($resize_pct < 0 or $resize_pct > 100) die("bad resize value $resize_pct!");

            $img = imagecreatefromjpeg($upload['tmp_name']);
            if (!$img) die('error processing image');
            $dims = getimagesize($upload['tmp_name']);

            $newx = sprintf('%d',$dims[0] * $resize_pct / 100);
            $newy = sprintf('%d',$dims[1] * $resize_pct / 100);

            $newimg = imagecreatetruecolor($newx,$newy);
            imagecopyresampled($newimg,$img,0,0,0,0,$newx,$new y,$dims[0],$dims[1]);

            # test output
            header("content-type: image/jpeg");
            imagejpeg($img);
            --------------------------------------------------------

            If you are using the same watermark or have a watermark graphic your best bet is to combine the images together.

            ca3.php.net/manual/en/function.imagecopymerge.php
            Has example.

            If you want to use truetype or postscript fonts (requires external libraries).

            ca3.php.net/manual/en/function.imagettftext.php
            ca3.php.net/manual/en/function.imagepstext.php

            A more bare bones approach could use the imagechar or imagestring functions.

            ca3.php.net/manual/en/function.imagechar.php
            ca3.php.net/manual/en/function.imagestring.php
            MySQL | Perl | PHP Developer cal [@] asacp [.] org

            Comment

            • ASACP Cal
              Registered User
              • Jun 2007
              • 6

              #7
              minor correction

              it should read imagejpeg($newimg) at the end of the code snippet.

              to write to a file remove the header("content-type: image/jpeg");
              and change imagejpeg($newimg) to imagejpeg($newimg,"some/image/path");

              you'd want to do any other transformations after the imagecopyresampled function.
              MySQL | Perl | PHP Developer cal [@] asacp [.] org

              Comment

              • Goodings Media
                Confirmed User
                • Apr 2007
                • 1987

                #8
                woah dude, thanks
                ICQ: 446-568-913 Email: liam||goodingsmedia.com msn: [email protected]

                Comment

                Working...