Solved

PHP GD Library

Posted on 2011-02-18
7
802 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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 108

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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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 is …
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…
The viewer will learn how to dynamically set the form action using jQuery.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now