Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 707581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:17:38+00:00 2026-05-14T04:17:38+00:00

I have a cool snippet of code that works well, except one thing. The

  • 0

I have a cool snippet of code that works well, except one thing.

The code will take an icon I want to add to an existing picture. I can position it where I want too! Which is exactly what I need to do.

However, I’m stuck on one thing, concerning the placement.

The code “starting position” (on the main image: navIcons.png) is from the Bottom Right.

I have 2 variables: $move_left = 10; & $move_up = 8;.
So, the means I can position the icon.png 10px left, and 8px up, from the bottom right corner.

I really really want to start the positioning from the Top Left of the image, so I’m really moving the icon 10px right & 8px down, from the top left position of the main image.

Can someone look at my code and see if I’m just missing something that inverts that starting position?

<?php

function attachIcon($imgname)
{
    $mark = imagecreatefrompng($imgname);
 imagesavealpha($mark, true);

    list($icon_width, $icon_height) = getimagesize($imgname);

    $img = imagecreatefrompng('images/sprites/navIcons.png');
 imagesavealpha($img, true);

    $move_left = 10;
    $move_up = 9;

    list($mainpic_width, $mainpic_height) = getimagesize('images/sprites/navIcons.png');
    imagecopy($img, $mark, $mainpic_width-$icon_width-$move_left, $mainpic_height-$icon_height-$move_up, 0, 0, $icon_width, $icon_height);
    imagepng($img);  // display the image + positioned icon in the browser
  //imagepng($img,'newnavIcon.png'); // rewrite the image with icon attached.
}

header('Content-Type: image/png');
 attachIcon('icon.png');
?>

For those who are wondering why I’d even bother doing this. In a nutshell, I like to add 16×16 icons to 1 single image, while using css to display that individual icon. This does involve me downloading the image (sprite) and open photoshop, add the new icon (positioning it), and reuploading it to the server. Not a massive ordeal, but just having fun with php.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:17:38+00:00Added an answer on May 14, 2026 at 4:17 am
    bool imagecopy  (  resource $dst_im  ,  resource $src_im  ,  int $dst_x  ,  int $dst_y  ,  int $src_x  ,  int $src_y  ,  int $src_w  ,  int $src_h  )  
    

    Copy a part of src_im onto dst_im starting at the x,y coordinates src_x, src_y with a width of src_w and a height of src_h. The portion defined will be copied onto the x,y coordinates, dst_x and dst_y. (PHP.net

    $move_right = 10;
    $move_down = 8;    
    imagecopy($img, $mark, $move_right, $move_down, 0, 0, $icon_width, $icon_height);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a cool script that works with two buttons. I need to add
On MDC's site they have a cool demo of dispatchEvent that works fine in
I have this cool little snippet that I found, which adds a shadow to
Does anyone have a suggestions for a superb cool image gallery that I can
I have an application that will record and play audio files. Some of the
I have the following code snippet, which loads data from a CSV file into
So I have a cool one for ya. I need to scan my html
Another simple question. I found this really cool snippet of code: $date_str = Jan
I have a really cool website that allows people to upload images. Sometimes there
We have a pretty cool little web framework that we have used successfully on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.