SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot asrasrasr's Avatar
    Join Date
    Apr 2009
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Php code set a canvas area arount the image

    Hello Everybody,


    i want to add a canvas area or white area around the jpeg image on the fly using php script. Are this possible.

    Please help me this is urgent.
    Thanks in advance

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    http://us3.php.net/imagecopy

    Allocate an image that's several pixels taller and wider than the original, and make your copy offset from the corner by half as many pixels.

  3. #3
    SitePoint Zealot asrasrasr's Avatar
    Join Date
    Apr 2009
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your quick response.

    I have used imagecopy() function use the following code.

    Code PHP:
    <?php
    // Create image instances
    $src = imagecreatefromjpeg(' www ndesign-studio com/images/portfolio/illustration/nature-1.jpg');
    $dest = imagecreatetruecolor(570, 420);
    // Copy
    imagecopy($dest, $src, 10, 10, 20, 13, 550, 400);
     
    // Output and free from memory
    header('Content-Type: image/jpeg');
    imagejpeg($dest);
     
    imagedestroy($dest);
    imagedestroy($src);
    ?>

    But this code give a black color back of copied image. can this become white.

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    http://ee.php.net/manual/en/function...drectangle.php

    Draw a white rectangle the size of the image before copying over it.

  5. #5
    SitePoint Zealot asrasrasr's Avatar
    Join Date
    Apr 2009
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dan .
    I have use imagefill() function.
    But i dont know why this become with red and black color background .
    But i want only red color. Plz solve my this problem
    the code is:

    Code PHP:
    <?php
    // Create image instances
    $src = imagecreatefromjpeg(' www ndesign-studio.com/images/portfolio/illustration/nature-1.jpg');
     
    $im = imagecreatetruecolor(570, 420);
    // sets background to red
    $red = imagecolorallocate($im, 255, 0, 0);
     imagefill($im, 0, 0, $red);
     
    //$dest = imagecreatetruecolor(570, 420);
    // Copy
    imagecopy($im, $src, 10, 10, 20, 13, 550, 400);
     
    // Output and free from memory
    header('Content-Type: image/jpeg');
    imagejpeg($im);
     
    imagedestroy($im);
    imagedestroy($src);
    ?>

  6. #6
    SitePoint Zealot asrasrasr's Avatar
    Join Date
    Apr 2009
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dan problem short out.


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
  •