Solved

PHP GD Library

Posted on 2011-02-18
7
806 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

710 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