Categories
PHP
Javascript
MySQL
C#
VB
VB.NET
ASP.NET
Regex
Packaging & compression
General Web Tech
Tech Speak


Google


This website looks best on firefox.
 
Resource Center : PHP : <PHP Imaging support & Image manipulation - An overview of possibilities>

PHP Imaging support & Image manipulation - An overview of possibilities

Posted by: Floresense Team
Pages: 1  2  3  4  

 

Image zooming / enlarging:

Zooming (technical zooming, not practical zooming) is done by enlarging a part of the source image. This can again be done by using the same code as for image resizing, except that we select a portion of source image for resize rather than the full source image.

Also, since we are not interested in resizing the image but only zooming the content, destination image size parameters will be same as source image parameters
  $dst_width = $src_width;
  $dst_height = $src_height;
  imagecopyresized($thumb_im, $src_im, 0, 0, 100, 10,
                     $dst_width, $dst_height,
                     50, 50);



Image Cropping:

Cropping of images again can be done with the imagecopyresized method itself. The only difference is we actually dont resize but copy the part of the image where it has to be cropped.

  $cropped_im = imagecreatetruecolor($src_width-100,$src_height-100);
  //we use imagecreatetruecolor instead of imagecreate to preserve colors
  //during resize.
  
  // Resize
  imagecopyresized($cropped_im, $src_im, 0, 0, 100, 100,
                     $src_width-100, $src_height-100,
                     $src_width-100, $src_height-100);


Image Rotation:

Rotation can be done with the method imagerotate().

Syntax: resource imagerotate ( resource src_im, float angle, int bgd_color )

This method Rotates the src_im image using a given angle in degrees. bgd_color specifies the color of the uncovered zone after the rotation. The center of rotation is the center of the image, and the rotated image is scaled down so that the whole rotated image fits in the destination image - the edges are not clipped.

  $rotateDeg = 8;
  // Rotate
  $dst_im = imagerotate($src_im,$rotateDeg,0);



The rotated portion of the images appear dark because we mentioned '0' as the last parameter in imagerotate() which stands for black color background after rotation.

Drawing True-Type Fonts:

The imagestring() method can be used to draw fonts, but it limits use within a very few in-built fonts in PHP. With the FreeType library in PHP we can draw true-type fonts, like Arial, Verdana, Gothic, Lucida, Comic sans, etc.,

You should have the .ttf files of the respective fonts for creating text in those fonts. If you are using a windows machine, these ttf files will be available on your machine, since windows uses true-type fonts for everything.

But, if you are working on a linux machine, you might have to check for .ttf files or use something downloaded from the web. Care is to be taken since, some true-type fonts have copyrights.

On my windows machine, below code generates a TTF styled text message as an image.
<?php
$fontFile = "fonts/LHANDW.TTF";
$im = imagecreate(110,50);
$bgcolor = imagecolorallocate ($im,255,255,255);
$forecolor = imagecolorallocate ($im, 0, 0, 0);
//fontSize, rotationAngle, xPos, yPos
imagefttext($im,11,8,30,20,$forecolor,$fontFile,"Welcome!");
header ("Content-type: image/gif"); //header
imagegif($im);
imagedestroy($im);
?>
Pages: 1  2  3  4  

Advertisement

2005 - 2008 © Floresense.com