creating thumbnails
Moderator: General Moderators
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
creating thumbnails
how can I create thumbnails for .jpg and .png files?
Code: Select all
$destimg = imagecreatetruecolor ($newWidth, $newHeight)
or die ("Problem In Creating image"); // Create thumbnail canvas
// Use one or use conditional to select i.e. if JPEG
$srcimg = imagecreatefromjpeg ("path to full sized")
or die ("Problem In opening Source Image"); // For JPEG
// else PNG
$srcimg = imagecreatefrompng ("path to full sized")
or die ("Problem In opening Source Image"); // For PNG
imagecopyresampled ($destimg, $srcimg, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height)
or die ("Problem In resizing"); // Resample the image from $srcimg to the $destimg
// Use one or use conditional to select i.e. if JPEG
imagejpeg ($destimg, "path to thumb") or die("Problem In saving"); // Save JPG
// else PNG
imagepng ($destimg, "path to thumb") or die("Problem In saving"); // Save PNG-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
I got this and its not saving the file to the server.
[/url]
Code: Select all
<?php
$destimg = imagecreatetruecolor (250, 250)
or die ("Problem In Creating image"); // Create thumbnail canvas
// Use one or use conditional to select i.e. if JPEG
$srcimg = imagecreatefromjpeg ("uploads/boo.jpg")
or die ("Problem In opening Source Image"); // For JPEG
imagecopyresampled ($destimg, $srcimg, 0, 0, 0, 0, 250, 250, 494, 733)
or die ("Problem In resizing"); // Resample the image from $srcimg to the $destimg
// Use one or use conditional to select i.e. if JPEG
imagejpeg ($destimg, "uploads/tester.jpg") or die("Problem In saving"); // Save JPG
?>is your upload folder chmod 0777?
put it this way, it works for me on mine http://www.saxonian.co.uk/imagehost/ , also try full paths so /home/you/public_html/ .... /uploads/ thats what i use.
Edit: found your problem you should use relative paths properly
don't forget the ./ before the path, either that or use full paths.
put it this way, it works for me on mine http://www.saxonian.co.uk/imagehost/ , also try full paths so /home/you/public_html/ .... /uploads/ thats what i use.
Edit: found your problem you should use relative paths properly
Code: Select all
<?php
$destimg = imagecreatetruecolor (250, 250)
or die ("Problem In Creating image"); // Create thumbnail canvas
// Use one or use conditional to select i.e. if JPEG
$srcimg = imagecreatefromjpeg ("./uploads/boo.jpg")
or die ("Problem In opening Source Image"); // For JPEG
imagecopyresampled ($destimg, $srcimg, 0, 0, 0, 0, 250, 250, 494, 733)
or die ("Problem In resizing"); // Resample the image from $srcimg to the $destimg
// Use one or use conditional to select i.e. if JPEG
imagejpeg ($destimg, "./uploads/tester.jpg") or die("Problem In saving"); // Save JPG
?>-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
list ($width, $height) = getimagesize("./uploads/boo.jpg");
// $width file width
// $height file height-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
-
mparker1113
- Forum Commoner
- Posts: 28
- Joined: Wed Apr 05, 2006 9:39 am
I would like to catch and resize photos from file input stat
from file input status, before i move them to a different directory using moveuploadedfile() or other means.
I think that the photos directly from the camera are to big to be moved, and would like to resize them immediately, so that I can move them.
would the code for this be similar to the posted, using imagecreatefromjpeg, and makejpeg() ?
Would I be able to get this to work, (without storing the file first)?
Thanks for input.
Mike
I think that the photos directly from the camera are to big to be moved, and would like to resize them immediately, so that I can move them.
would the code for this be similar to the posted, using imagecreatefromjpeg, and makejpeg() ?
Would I be able to get this to work, (without storing the file first)?
Thanks for input.
Mike
- aerodromoi
- Forum Contributor
- Posts: 230
- Joined: Sun May 07, 2006 5:21 am
As always: The beauty lies in the eye of the beholderpsychotomus wrote:yes... what should i thumbnail them to?
If you really want square shaped thumbnails, you'll have to resize them to a certain size, which is somewhat bigger than the final size. You can then crop them by using ImageCopy();
aerodromoi
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
I get this error when trying to resize an image after uploading it.
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /mounted-storage/home16a/sub002/sc18478-RGIJ/www/admin_wallpapers.php on line 196
Problem In resizing
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /mounted-storage/home16a/sub002/sc18478-RGIJ/www/admin_wallpapers.php on line 196
Problem In resizing
Code: Select all
$loc = $row['id'] + 1;
if (move_uploaded_file($_FILES["file"]["tmp_name"], "./wallpapers/" . $loc . '.jpg'))
{
//SAVE THUMBNAIL
$srcimg = imagecreatefromjpeg ("./wallpapers/" . $loc . '.jpg')
or die ("Problem In opening Source Image"); // For JPEG
imagecopyresampled ($destimg, $srcimg, 0, 0, 0, 0, 150, 150, imagesx($srcimg) , imagesy($srcimg))
or die ("Problem In resizing"); // Resample the image from $srcimg to the $destimg
imagejpeg ($destimg, "./wallpapers_thumbs/" . $loc . ".jpg") or die("Problem In saving"); // Save JPG- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Nice code. First time I've seen "list" used well.$phpNut wrote:and your not thumbnailing them to a square are you? ie distorting images and generally making them look horribleCode: Select all
list ($width, $height) = getimagesize("./uploads/boo.jpg"); // $width file width // $height file height
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
- xpgeek
- Forum Contributor
- Posts: 146
- Joined: Mon May 22, 2006 1:45 am
- Location: Kyiv, Ukraine
- Contact:
Re: creating thumbnails
use http://phpthumb.sourceforge.net/.psychotomus wrote:how can I create thumbnails for .jpg and .png files?
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
my code is fine. its almost exactly how coppermine is done but without a class.
since im using HTTP POST to get the filename, how can i replace this and set $srcimg to the $_FILES['file'] which is allready in memory instead of loading the file and using up twice as much memory. maybe I can get it to work that way.
$srcimg = imagecreatefromjpeg ("./wallpapers/" . $loc . '.jpg') or die ("Problem In opening Source Image"); // For JPEG
since im using HTTP POST to get the filename, how can i replace this and set $srcimg to the $_FILES['file'] which is allready in memory instead of loading the file and using up twice as much memory. maybe I can get it to work that way.
$srcimg = imagecreatefromjpeg ("./wallpapers/" . $loc . '.jpg') or die ("Problem In opening Source Image"); // For JPEG