Latest Post
Tampilkan postingan dengan label image resize. Tampilkan semua postingan
Tampilkan postingan dengan label image resize. Tampilkan semua postingan

Image Upload and Cropping with PHP and Jquery

Written By Unknown on Minggu, 18 Maret 2012 | 09.51

Image cropping is the most important and required part in social media projects. In this post my friend had implemented image cropping functionalities such as upload image file into physical location, cropping image using jquery and resizing image into small resolution.



To read more about this article Click Here

For Demo Click Here

Resize images with PHP script

Written By Unknown on Jumat, 27 Mei 2011 | 11.49


This small command line PHP script will help you to resize all JPG images inside current directory. Yes, you will find a lot of solutions with BASH scripts, but I decided to write my own command line PHP script. I didn't want to use GD PHP functions for image processing. 


Instead of GD library, I used utilities from ImageMagick suite of tools: identifyand convert. This way, PHP script is shorter and easier to understand.
  • identify - describes the format and characteristics of one or more image files
  • convert - convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more
Script was developed on Linux - Fedora Core 9 and tested on Fedora Core 9 and Fedora Core 10.

#!/usr/bin/php
<?
/*
 * usage:
 * resize.php [destination_width] [destination_height]
 *
 * destination_width and destination_height are optional
 * parameters for destination resize geometry
 *
 * resize.php will create output directory to save resized
 * images leaving originals intact
 *
 * This script uses "identify" and "convert" utilities which
 * are members of the ImageMagick suite of tools
 *
 */

// input arguments for destination image size
$w2 = $argv[1]; // image width
$h2 = $argv[2]; // image height

// both values should be numeric or use default size 800x600
if (!is_numeric($w2) || !is_numeric($h2)){
    $w2 = 800; // default image width
    $h2 = 600; // default image height
}

// prepare directory name for saving resized images
// directory name will look like "_800x600"
$dir = "_$w2" . "x$h2";

// create directory (inside current directory) for saving
// resized images (@ means to be quiet - don't display
// warning if directory alredy exists)
@mkdir($dir);

// read files inside current directory
$files = scandir('.');

// open loop for all fetched files in current directory
foreach ($files as $file){
    // convert file name to lower case
    $file_lowercase = strtolower($file);
    // if file extension is jpg then process image
    if (substr($file_lowercase, -3) == 'jpg'){
        // describe image format and image characteristics
        $identify = shell_exec("identify $file");
        // read image geometry
        preg_match('/(\d+)x(\d+)/', $identify, $matches);
        $g1 = $matches[0]; // image geometry
        $w1 = $matches[1]; // image width
        $h1 = $matches[2]; // image height
        // prepare destination image geometry
        if ($w1 < $h1) $g2 = $h2 .'x' .$w2;
        else           $g2 = $w2 .'x' .$h2;
        // print current image status
        print "$file ($g1) -> $dir/$file_lowercase ($g2)\n";
        // resize image and save to destination directory
        system("convert -size $g1 $file -resize $g2 $dir/$file_lowercase");
    }
}
?>


If you want to try script, please save PHP code as resize.php. Set permissions to 755 and you can start resize.php like any script from the shell.
Enjoy!

Simple Image Resize Calculator Function

Written By Unknown on Rabu, 14 April 2010 | 23.11


Here is a simple function to calculate the width and height of an image given the constraints you want the image to fit in. This is great for creating thumbnails which need to fit into a specific height / width.

To call the function, pass in the current height / width of the image you’d like to resize along with the constrain dimensions of the final product. In this case, I’d like the thumbnail to fit within the constraints 125px X 125px. So, no matter what the dimensions returned will be within those confines.
If you don’t pass along a $constraintWidth or $constraintHeight [or pass them as 0], they will be set to the $width / $height.
Also, all parameters are assumed to be of the strict type int.
<?php
function getImageResizeDimensions($width,$height,$constraintWidth = 0,$constraintHeight = 0) {
$constraintWidth = ($constraintWidth === 0) ? $width : $constraintWidth;
$constraintHeight = ($constraintHeight === 0) ? $height : $constraintHeight;
if (($width > $constraintWidth) || ($height > $constraintHeight)) {
while (($constraintWidth < $width) || ($constraintHeight < $height)) {
if ($constraintWidth < $width) {
$height = floor((($constraintWidth * $height) / $width));
$width = $constraintWidth;
}
if ($constraintHeight < $height) {
$width = floor((($constraintHeight * $width) / $height));
$height = $constraintHeight;
}
}
retur
}
n array ($width,$height);
}
$imageURI = "/path/to/image.jpg";
list ($width,$height) = getimagesize($imageURI);
list ($newWidth,$newHeight) = getImageResizeDimensions($width,$height,125,125);
echo "newWidth: $newWidth\n";
echo "newHeight: $newHeight\n";
?>
 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger