![]() fit_to_height() - proportionally resizes an image to the specified height.fit_to_width() - proportionally resizes an image to the specified width.resize() - resizes an image to the specified width/height.auto_orient() - adjusts the orientation based on the image's EXIF data.rotate() - rotates an image at the specified angle.flip() - flips an image vertically or horizontally.The following two lines will load image.jpg, flip it horizontally, rotate it 90 degrees, shrink it to fit within a 320x200 box, apply a sepia effect, convert it to a GIF, and save it to result.gif: $img = new SimpleImage('image.jpg') This class takes the headache out of dealing with images and features over 25 useful methods. If you love working with PHP but hate the GD library, you'll love the Simple Image PHP class I'm releasing today. I keep posts like this around for historical purposes and to prevent link rot, so please keep this in Rotate an image 90 degrees right (clockwise).Heads up! This post was written in 2011, so it may contain information that is no longerĪccurate. Rotate an image 90 degrees left (counter-clockwise). For example if you want to allow users to generate a 50x50 profile thumbnail on every crop then use target width and height. Target Width and Height are optional and can be used to force images to a specific size. For example allow a user to crop an uploaded image to a profile thumbnail. This can be used with JavaScript or App cropping libraries to allow users to generate thumbnails from a full uploaded image. Returns: $this crop($left, $top, $width, $height, $target_width = null, $target_height = null) If only width or only height are specified then image will be sized to that value. When both width and height are specified the image will be sized to the smaller of the two values so it fits. Resize an image to a specified max width and height. Returns: $this resize($max_width = null, $max_height = null) Opening a image requires PHP 5.4 or greater. If the file contains an invalid image then an E_WARNING error will be triggered causing an ErrorException to be thrown when using the default error setup. Image type is determined by the file extension. Open a image file (jpg, png, gif, or webp). This happens automatically when the variable is no longer used.Ĭlass Constructor - Optionally open an image _destruct()Ĭlass Destructor - Free memory by closing image when done. Optionally close the image to free memory when finished working with it. a path or save to a new file by specifying a full file path. Overwrite an existing image by simply calling without $img->pngCompression(6) // Default Compression-Level And Compression-Level (0 to 9) can be specified when saving PNG files. Save Quality (0 to 100) can be specified when saving JPG or WEBP images. the mobile device or a user may simply want to change the rotation. images because images can often upload with incorrect rotation depending on Images can be rotated which is useful for sites that allow users to upload $img->crop($left, $top, $width, $height, $target_width, $target_height) a user to crop an uploaded image to a profile thumbnail. to generate thumbnails from a full uploaded image. This can be used with JavaScript or App cropping libraries to allow users Images can also be cropped to a specific dimension. specified then image will be sized proportionally to the value. When both width and height are specified the image will be sized to the Generate a Thumbnail or Resize the Image to a specified max width and height. file extension doesn't match the file type then an exception will be thrown. رمز المثال Open and Edit Images Files // Use the Media Image Class to open an image. It is intended to provide needed core functionally when working with image file uploads and for thumbnail generation.įor additional PHP image libraries see the following projects: Source Code This class provides basic functionally and is not full featured with filters or advanced features. Allow an image file to be opened, manipulated, and saved.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |