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
Solved

PHP GD Library

Posted on 2011-02-18
7
804 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
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 9

Accepted Solution

by:
AriMc earned 500 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 109

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

789 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