PHP GD - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

PHP GD

Description:

Blogger, Flickr, &c all make thumbnails at the point of upload. ... img, type BLOB. Click the INSERT tab. Upload an image from your desktop to your database ... – PowerPoint PPT presentation

Number of Views:138
Avg rating:3.0/5.0
Slides: 21
Provided by: Stude8
Category:
Tags: php

less

Transcript and Presenter's Notes

Title: PHP GD


1
PHP GD MYSQL
  • Image Processing
  • Database Storage

2
Why Process Images
  • Automatic Watermarks
  • Watermark images viewed on free page
  • Unmarked image on pay-for page
  • Resize images on the fly
  • Thumbnail / Gallery View
  • Custom images for mobile devices
  • Create charts and graphs on the fly with dynamic
    data

3
Process Once or at Every Request
  • Blogger, Flickr, c all make thumbnails at the
    point of upload.
  • For high volume operations, disk space is always
    cheaper than processor time
  • Processing Requests on the fly necessary if you
    are customizing images every time they are loaded
  • Charts are updated after a set duration

4
Creating Images
  • imagecreatefromjpeg(path_to_file)
  • Creates an image object using a preexisting image
    file
  • There are functions for png, gif, bmp c
  • imagecreatetruecolor(height, width)
  • Creates new image object
  • imagecreatefromstring(binary_data)

5
Image Properties
  • imagesx(image_resource)
  • Returns the width (in pixels) of an image object
  • imagesy(image_resource)
  • Returns the height of an image object
  • Aspect Ratio x/y or w/h
  • When resizing images, aspect ratio must be
    maintained

6
Outputting Images
  • imagejpeg(image_resource)
  • Outputs a jpeg format image to the browser
  • Other functions for png, gif, bmp c
  • imagejpeg(image_resource, path_to_file)
  • Saves image to the server

7
A Lame Example
  • (doesnt do anything we havent seen before)

http//www.rpi.edu/gillw3/websys/gd/lame.php
8
A Dorky Example
http//www.rpi.edu/gillw3/websys/gd/dorky.php
9
Image Processing
  • imagecopyresampled(lotsofargs)
  • Used to resize an image
  • imagecopymerge(lotsofargs)
  • Used to place an image on top of another
  • imagefilter(lotsofargs)
  • Manipulates the content of an image

10
Water Mark Example
  • PHP.NET
  • http//us.php.net/manual/en/image.examples.merged-
    watermark.php

11
A Graph Example
0,0
100,100
12
A Graph Example
  • http//www.rpi.edu/gillw3/websys/gd/graph.php

13
In Class Work
  • Improve my graph code
  • Find the extreme values in the array
  • Use imagesx() and imagesy() and count() to force
    the array data to fill any graph size

14
Storing Images in Databases
  • Binary Data can be stored in fields with a blob
    type
  • Other data to store
  • File type (.jpg, png)
  • File size
  • Original file name
  • EXIF data
  • This data can be lost after GD functions are run

15
Uploading Images
  • ltinput typefile namemyfilegt
  • Creates that include a file input box in an html
    form
  • The form must have
  • method post
  • enctype multipart/form-data

16
Processing the Form
  • Image is stored on server in a TMP directory
  • _FILES accesses files posted to the server
  • _FILES'userfile''name' name of file on the
    client
  • _FILES'userfile''type' file mimetype
  • _FILES'userfile''size' file size
  • _FILES'userfile''tmp_name' name of file on
    the server
  • MORE
  • http//us.php.net/features.file-upload

17
Putting Uploaded File into MYSQL
  • Open the uploaded file fopen()
  • Read it in to a string fread()
  • Use that string in an MYSQL INSERT command

18
Getting Images Out of MYSQL
  • Create a PHP image object from DB output
  • Imagecreatefromstring(rowimg)
  • Unlike other Imagecreate functions, it
    auto-detects the image encoding type

19
PHP GD / MYSQL
  • An Example
  • http//www.rpi.edu/gillw3/websys/gd/dbgd.php

20
Put an Image in a Database
  • In PHPMYADMIN
  • Create a table called images
  • Add two fields
  • id, type INT Auto-inc
  • img, type BLOB
  • Click the INSERT tab
  • Upload an image from your desktop to your database
Write a Comment
User Comments (0)
About PowerShow.com