Solved

PHP GD Library

Posted on 2011-02-18
7
805 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 110

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: 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.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

762 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