SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    create a background for image

    Hi,

    I have $new_img = ImageCreateTrueColor(95, 75);

    I want to create a 600x400 black background for the #new_img, then center the $new_img vertically and horizontally inside the background.

    which function can help me do this ?

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off the top of my head, I think you could just create the black image, and then use imagecopy() to copy the other image into it. dst_y and dst_x would be the upper left coordinates of where you want the small image to be placed.

    Btw- you could do this with css.

  3. #3
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,443
    Mentioned
    82 Post(s)
    Tagged
    3 Thread(s)
    The easy way is use Imagemagick

    With GD you will need to:

    Get the size of the large image and the small image.

    Take the width of the small image from the width of the large image then divide it by 2 - this will be your "x" position.

    Do the same for the height to get your "y" position.

    Then use: imagecopymerge()

    A couple of GD examples on my site: http://www.rubblewebs.co.uk/imagemagick/GDexamples.php & http://www.rubblewebs.co.uk./imagemagick/compair.php
    Last edited by Rubble; May 15, 2009 at 07:55. Reason: Added second link

  4. #4
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post

    Btw- you could do this with css.
    Yes this can be done with css, I just forget that LOL.

    @Rubble: thank you very much, will play it next time, at the moment i'm going with the css solution.


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
  •