PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 11, 2022

[FIXED] How to create thumbnail images with white 3px border using PHP?

 October 11, 2022     gd, image, php     No comments   

Issue

How to create thumbnail images with white 3px border using PHP?


Solution

Haven't actually tried this but I think something like this might work

<?php

/*
* Function to create a border around an image
*/
function drawBorder($image_name, $r = 0, $g = 0, $b = 0, $thickness = 1)
{
  $image = ImageCreateFromJPEG($image_name);
  $color = ImageColorAllocate($img, $r, $g, $b);

  $x1 = 0;
  $y1 = 0;
  $x2 = ImageSX($image) - 1;
  $y2 = ImageSY($image) - 1;

  for($i = 0; $i < $thickness; $i++)
  {
    ImageRectangle($image, $x1++, $y1++, $x2--, $y2--, $color);
  }

  return $image;
}

?> 

Then run something like

<?php
header('Content-type: image/jpeg');
ImageJPEG(drawBorder("images/foo.jpg", 128, 128, 0, 3));
?>


Answered By - inquam
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing