Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP GD Library

Posted on 2011-02-18
7
Medium Priority
?
808 Views
Last Modified: 2012-05-11
Hi i searching for some script which will create a small 1 pixel border around image. I need to save this image on  server so i can use it in future.
0
Comment
Question by:umaxim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Expert Comment

by:TimBare
ID: 34928019
out of curiosity, why do you want to alter the original image, rather than using css to add a single pixel border around a <img> tag?
0
 
LVL 9

Expert Comment

by:AriMc
ID: 34928023
Save your image in GIF-format as /tmp/logo.gif and run the following. Your "framed" image will be in /tmp/logo2.gif.




$im = ImageCreateFromGIF('/tmp/logo.gif');
   $rx = ImageSX($im)-1;
   $ry = ImageSY($im)-1;
   $tc = ImageColorAllocate($im, 255, 0, 0);

   $values = array(
      0, 0,
      $rx, 0,
      $rx, $ry,
      0, $ry,
      0, 0);

   ImagePolygon($im, $values, 5, $tc);
   ImageGIF($im, '/tmp/logo2.gif');
   ImageDestroy($im);

Open in new window

0
 
LVL 1

Author Comment

by:umaxim
ID: 34928135
what about jpeg image
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 9

Accepted Solution

by:
AriMc earned 2000 total points
ID: 34928243
For jpg, just replace the GIF-functions with jpg equivalents:


$im = ImageCreateFromJPEG('/tmp/logo.jpg');
   $rx = ImageSX($im)-1;
   $ry = ImageSY($im)-1;
   $tc = ImageColorAllocate($im, 255, 0, 0);

   $values = array(
      0, 0,
      $rx, 0,
      $rx, $ry,
      0, $ry,
      0, 0);

   ImagePolygon($im, $values, 5, $tc);
   ImageJPEG($im, '/tmp/logo2.jpg');
   ImageDestroy($im);

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34930347
I think I would choose CSS.  But the question is not complete.  Do you have a test image?  Please post one for us to use as test data.  Please tell us if you want the border to add to the size of the image or overwrite the existing order pixels.

If you are processing only a few images, you might just use Photoshop, too.
0
 
LVL 9

Expert Comment

by:AriMc
ID: 34930818
The author mentions the image should be saved on the server for future use. IMHO this indicates it is not an issue of modifying an image on-the-fly for a web server to be sent further but for something else. PHP, GD etc. can be and are used to perform off-line tasks too without any connection to web-servers, HTML or CSS.

0
 
LVL 1

Author Closing Comment

by:umaxim
ID: 34947266
Thank you very much
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question