This is a discussion on Image handling in php within the PHP Programming forums, part of the Web Development category; hi How to create jpeg image in PHP....
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi Varghese, Please view this link it can help to know more to create thumbnail whatever it is either jpeg or gif Article - How to create thumbnails with PHP and gd. For simple we can header("Content-type: image/jpeg"); $im = @imagecreate(100, 50) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 255, 255, 255); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5, "A Simple Text String", $text_color); imagejpeg($im); imagedestroy($im); i think it will help you
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| You can create thumbnail image with the use of imagecopyresampled method. This is one GD image library method. In this method just mention the source and destination location with specific width and height. With this you can create thumbnail of any image. Sample is as follow. <?php // The file $filename = 'test.jpg'; $percent = 0.5; // Content type header('Content-type: image/jpeg'); // Get new dimensions list($width, $height) = getimagesize($filename); $new_width = $width * $percent; $new_height = $height * $percent; // Resample $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Output imagejpeg($image_p, null, 100); ?> |
| |||
| Varghese, You can also use Imagemagick library for image manipulations. Imagemagick is much faster with better quality compared to GD library.
__________________ None of us is As Strong as All of us. |
| |||
| Hi Add the destination path in output for example if you want to store the image in the same location then <?php // The file $filename = 'test.jpg'; $percent = 0.5; // Get new dimensions list($width, $height) = getimagesize($filename); $new_width = $width * $percent; $new_height = $height * $percent; // Resample $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Output imagejpeg($image_p, $filename, 100); ?> The above code will save the image in jpg format with the file name 'test.jpg'. Thanks |
| |||
| Varghese In ImageJPEG function we just have to remove the null parameter and put the destination path. As i stated in bold red color, just put the destination path in that variable it will store the image in that specified location. imagejpeg($image_p, $filename, 100); |
| |||
| Creating images with Imagemagick is very easy. <? $ImgPath = "test.jpg"; $newWidth = 150; $newHeight = 150; //# -- Reads the jpg image $ImgHandler = Imagick_readimage($ImgPath); //#-- function used to resize the image Imagick_sample($ImgHandler, $newWidth, $newHeight ,"100x100"); $DestImgPath = "newimage.jpg"; //#-- Writes the image as newimage.jpg Imagick_writeimages($ImgHandler,$DestImgPath); ?> The above code will reads an image and saves into a specific location with a new name.
__________________ None of us is As Strong as All of us. |
| |||
| Imagemagick creates the images much faster when compared to GD library. Also GD creates the image with 72 DPI only, where as Imagemagick holds the actual DPI of the original image to the newly created images. Thus Imagemagick is much better than GD library.
__________________ None of us is As Strong as All of us. |
| |||
| Kathir As above anand specified you can create image with the help of Imagick read and write. <? //Specify image name and set desired height and width $ImgPath = "test.jpg"; $newWidth = 150; $newHeight = 150; //# -- Reads the jpg image $ImgHandler = Imagick_readimage($ImgPath); //#-- function used to resize the image Imagick_sample($ImgHandler, $newWidth, $newHeight ,"100x100"); $DestImgPath = "newimage.jpg"; //#-- Writes the image as newimage.jpg Imagick_writeimages($ImgHandler,$DestImgPath); ?> I used this and found it is much faster than GD and also the created image resolution having same DPI like the original image. This is not possible in GD. |
| |||
| Hi KK use the below sample to change the image DPI <? //Specify image name and set desired height and width $ImgPath = "test.jpg"; $newWidth = 150; $newHeight = 150; $horizontalDPI = 400; $verticalDPI = 400; //# -- Reads the jpg image $ImgHandler = Imagick_readimage($ImgPath); //#-- function used to resize the image Imagick_sample($ImgHandler, $newWidth, $newHeight ,"100x100"); $DestImgPath = "newimage.jpg"; //#-- set the image Horizontal and Vertical dots per inch Imagick_setdpi ( $ImgHandler, $horizontalDPI,$verticalDPI ) //#-- Writes the image as newimage.jpg Imagick_writeimages($ImgHandler,$DestImgPath); ?> Thanks |
![]() |
| Thread Tools | |
| Display Modes | |
| |
LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/php-programming/3146-image-handling-php.html | |||
| Posted By | For | Type | Date |
| Anandkv's bookmarks on del.icio.us | This thread | Refback | 08-21-2007 06:32 AM |
| DiscussWeb IT Community - Fusing | This thread | Refback | 08-06-2007 03:07 AM |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Convert image to other image format using CODEC in .NET 3.0 | Mramesh | C# Programming | 0 | 02-07-2008 03:33 AM |
| How to create an image from panel background Image | S.Vinothkumar | C# Programming | 1 | 10-22-2007 03:52 AM |
| Error Handling in PHP | sivaramakrishnan | PHP Programming | 13 | 09-21-2007 05:03 AM |
| How can I do error handling in php? | itbarota | PHP Programming | 0 | 09-12-2007 12:39 AM |
| Image Handling in PERL | raj | Perl | 4 | 08-23-2007 12:23 AM |