VSource Web Solutions About Us  |  News  |  Contact Info  |  Network  |  Policies  |  Login  |  Support  |  Forum  |  (866) 346-9327


Online Demo



   
 
Search Documentation Search Documentation
 
   

Image Manipulation

   
 
Table Of Contents - Collapse

NEXT: Encrypting and Decrypting Data
 
   

Manipulating images has proven to be difficult at best when it comes to the web. This is because images can't just be uploaded and then the size set in HTML when a user views the image. This is because the image looks bad in the browser. The browser will simply distort the image and then you get jagged edges. You also run into more trouble when you try to make a photo gallery or image management software because the user usually wants to view the image at different sizes. Usually you would want a thumbnail image and a full size image. Plus, if you want to generate thumbnails of PDF documents, you are forced to do some major programming. Well, with VConsole, we do our best to make your job easy by proving a full suite of image manipulation tools.

Let's say that your VConsole application manages a list of clients. Now, you also want to give the capability for the user to upload a photo for each client and that photo should be used as a thumbnail in icon display mode and you should be able to click on a photo link to view a full size photo. Let's also say that you want the full size photo to be no larger than 500 x 500 and the thumbnail should be no larger than 100 x 100. Let's also say that you want to be able to create a photo from the first page of a PDF file if the user uploads a PDF file as a photo. Well, VConsole lets you do all of this fairly easily. If you take a look at the rest of the documentation, you will see that the Wizard Manager lets you upload files. You can also make sure that they have a certain file extension. Also, the Data Manager allows you to specify a thumbnail function. Now all that is left is for you to take the uploaded image, scale it, create a thumbnail, and store it somewhere where the thumbnail function can access it. So, how do you resize the image files and make thumbnails, you do it using the image manipulation functions listed below.

PHP Image Manipulation Functions.
These functions require that ImageMagick 6.3.9 or above. (Image Magick is required anyway for the image string validation on the login screen) Also, ImageMagick must be compiled with support for all the image formats that you want to support and if you want to create images from PDF files, you must have Ghostscript 8.15 or above installed as well. All of the listed functions return true on success or false on failure. Here is the function list.

  • make_thumbnail() - This function will make a thumbnail from any image or PDF file (if Ghostscript is installed). You call it like this:
    • make_thumbnail($error_msg, $file, $maxwidth, $maxheight, $file_output);
      • $error_msg - This will be set to the error message if the thumbnail fails to be generated.
      • $file - Set to the path of the file to generate the thumbnail from. (Path to file)
      • $maxwidth - The maximum width in pixels to make the thumbnail
      • $maxheight - The maximum height in pixels to make the thumbnail
      • $file_output - (Optional) The file to output the thumbnail to. (If not given, the original file is overwritten)
         
  • resize_image() - This function will resize any image. The original file is always overwritten. You call it like this:
    • resize_image($error_msg, $file, $width, $height, $maintain_aspect_ratio);
      • $error_msg - This will be set to the error message if any.
      • $file - The file to resize (Path to file)
      • $width - The resize width in pixels
      • $height - The resize height in pixels
      • $maintain_aspect_ratio - (Optional) Set this to true of false. Default is true
            If true, then the aspect ratio will be maintained and the image will be resized to fit the given rectangle ($width x $height)
            If false, then the image will be forced to be exactly $width x $height
         
  • scale_image() - This function will scale any image according to a percentage. The original file is always overwritten. You call it like this:
    • scale_image($error_msg, $file, $xscale, $yscale);
      • $error_msg - This will be set to the error message if any.
      • $file - The file to scale (Path to file)
      • $xscale - The X direction scale ratio to scale the image: MUST be greater or less than 100. Example: 200 - Double size, 50 scale by 1/2, etc...
      • $yscale - (Optional) The Y direction scale ratio to scale the image: MUST be greater or less than 100. Example: 200 - Double size, 50 scale by 1/2, etc...
            If you don't specify $yscale, then it is set to whatever you set the $xscale to.
         
  • optimize_image() - This function will optimize the image file for the web. Jpg images will be set to a quality of 70 and gif images will be set to use 256 colors. Other image types will not be optimized, so the file must be jpg or gif. Quality of files may degrade when using this function. You call it like this:
    • optimize_image($error_msg, $file);
      • $error_msg - This will be set to the error message if any.
      • $file - The file to optimize (Path to file)
         
  • convert_image() - This function will convert any image to any other format. The file will be converted and have the correct extension for the format requested. The extension will simply be appended to the input file string. Example: convert input.jpg to gif, output file will be input.jpg.gif. The input file must be one of the supported formats jpg gif tif png bmp pdf. If converting a pdf to another format, then the output file will be an image of only the 1st page. If converting an animated gif to another format, then the output file will be an image of only the 1st frame. (For converting from animated gif to pdf or pdf to animated gif, see the next function) You call it like this:
    • convert_image($error_msg, $file, $format);
      • $error_msg - This will be set to the error message if any.
      • $file - The file to convert. (Path to file)
      • $format - The format to convert to. Acceptable values are: jpg gif tif png bmp pdf
         
  • convert_gifpdf() - This function will convert an animated gif to a multi-page PDF file or from a multi-page PDF file to an animated gif. The file will be converted either to PDF or to GIF. If the input file is PDF, it will be converted to gif and visa versa. The input file MUST be either PDF or GIF format. The output file will have .gif or .pdf appended to the end of the filename. (Example: If converting input.gif to PDF format, the output file will be input.gif.pdf) You call it like this:
    • convert_gifpdf($error_msg, $file, $delay, $loop);
      • $error_msg - This will be set to the error message if any.
      • $file - The file to convert. (Path to file)
      • $delay - The delay in hundredths of a second for each frame. (Only when converting to animated gif)
      • $loop - Number of times to loop the animation (0 for infinite) (Only when converting to animated gif)
         
  • overlay() - This function will overlay 1 image on top of another. You can even set a transparency on the overlayed image so that the background image shows through. This is great for watermarks. You call it like this:
    • overlay($error_msg, $file, $overlay, $file_output, $gravity, $bgalpha, $ovalpha);
      • $error_msg - This will be set to the error message if any.
      • $file - The background image to overlay upon (Path to file)
      • $overlay - The overlay image to overlay over the $file image. (Path to file)
      • $file_output - The file to output to (Path to file)
      • $gravity - (Optional) The gravity of the overlay upon the background. defaults to NorthWest (Must be NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast)
      • $bgalpha - (Optional) The alpha of the background. defaults to 100 (no transparency) (Must be 0 to 100)
      • $ovalpha - (Optional) The alpha of the overlay. defaults to 100 (no transparency) (Must be 0 to 100)

NEXT: Encrypting and Decrypting Data


COMMENTS
 

There are no comments at this time.

Post Your Comment
 
Your Name*
Your Email Address* (Not Shown)
Your Comment (HTML OK)*
Enter the characters that you see here
Get New Image
*required fields