SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Merging two images in PHP specially with Imagic or Imagemagick commands !

    Hi folks,

    Can anyone suggest a link/page for merging two images into one using PHP's IMagick library or directly imagemagick commands? Actually what I want is; I have one image as background and another small iconic image of certain size (say 80x80px) to be placed in a certain specific area of the background image. I have a workaround to place the icon in a specific area of another image. See an example here and tryto customize a http://uno.chivasregal.info/products...tic-fancy-bags. I have stored the Pixel of the icon when it is dragged.

    Now in the checkout process, I want to generate the final design image as seen in the web page into another image. I don't know I explained it enough or not but what I want once again is: place one small image in a specific area of another bigger image and save to a new image.

    Please guide me in a right direction. I could not find any clue from Google. Actually I can do it using GD but I don't want to do it using Imagemagick. Lets say it is the requirement.

    Thanking you in advance !

    Regards
    Raju.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,191
    Mentioned
    71 Post(s)
    Tagged
    3 Thread(s)
    Try:

    PHP Code:
    <?php
    $background 
    '317ffd8c37.jpg';
    $top_image 'boots.png';

    exec("convert 317ffd8c37.jpg boots.png -gravity center -geometry +0+50 -composite output.jpg");
    ?>
    -gravity center puts the top image on the center of the base image; tweek the position with -geometry

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rubble View Post
    Try:

    PHP Code:
    <?php
    $background 
    '317ffd8c37.jpg';
    $top_image 'boots.png';

    exec("convert 317ffd8c37.jpg boots.png -gravity center -geometry +0+50 -composite output.jpg");
    ?>
    -gravity center puts the top image on the center of the base image; tweek the position with -geometry
    Thank you so much Rubble ! I will look at it then will revert back if there is anything ! Thanks
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Rubble,

    That worked quite good in this way. But why doesn't it work in windows with full path ?

    The following works:
    Code php:
    $background = "main.jpg";
    $top_image = "tomerge.png";
    $output = "output.png";
     
    exec("convert $background $top_image -gravity -geometry +0+0 -composite $output");
    header('Content-type: image/png');
    echo readfile($output);
    die;

    But the following does not work (please note the path of the images):
    Code php:
    $path = dirname(__FILE__);
    $background = "$path/images/main.jpg";
    $top_image = "$path/images/tomerge.png";
    $output = "$path/images/output.png";
     
    exec("convert $background $top_image -gravity -geometry +0+0 -composite $output");
    header('Content-type: image/png');
    echo readfile($output);
    die;

    I am in Windows 8 with Apache and PHP ! Is there any specific way of using paths in Windows? I tried D:\\etc\\path\\ and also D://etc//path but none of them worked.

    Thanking you once again for the help !
    Regards
    Raju
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry Rubble, after trying the whole day today and couple of hours yesterday, I figured it out that I had missed something. I had used -gravity but did not pass the value for it. That remained really pain in ass for last two days
    PHP Code:
    $path dirname(__FILE__);
    $background "$path/images/main.jpg";
    $top_image "$path/images/tomerge.png";
    $output "$path/images/output.png";

    exec("convert $background $top_image -geometry +0+0 -composite $output");
    header('Content-type: image/png');
    echo 
    readfile($output); 
    This works now quite good !

    Thanking you once again !

    Edit:
    By the way, is there a way to enable error message that Imagemagick itself returns and we can see on the screen on such mistakes ?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


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
  •