Log in

View Full Version : File resize?


ryan_f
09-10-2004, 23:29
Im working on a website right now and i made a script in php to upload an image and then display it on a different page. It works very well. My only problem is that i want to be able to turn those images into thumbnails with small file sizes automatically once i upload the file to my server. I don't really know that much php and i have no idea how i would accomplish this

JakeGallagher
09-10-2004, 23:33
I don't know a lot about php either, but I think I saw somewhere that Photoshop has a utility included in it somewhere that allows you to create php galleries similar to Windows Explorer Filmstrip picture viewing... does your team have a copy of PS? Maybe other editors have this same feature (Paint Shop Pro, CoredDRAW, etc.)
Check those out.

ryan_f
09-10-2004, 23:35
yes we do have a copy of photoshop but i've never heard of a utility like that. But i also do not know much about photoshop

Leonas
09-10-2004, 23:50
Download a copy of some forum software like Vbulletin, phpBB, or Invision, open it in Dreamweaver, and do a code search of the entire folder that you have to make into a site for "image resize" or "resize".

Joe Ross
10-10-2004, 01:00
you'll want another library such as GD or ImageMagick to do the resizing. Googling those should give you plenty of material to get you started.

Ian W.
10-10-2004, 01:12
Im working on a website right now and i made a script in php to upload an image and then display it on a different page. It works very well. My only problem is that i want to be able to turn those images into thumbnails with small file sizes automatically once i upload the file to my server. I don't really know that much php and i have no idea how i would accomplish this
Could you just use something like Gallery?

If not, I've done some work on that, you can check this link:

http://users.wpi.edu/~woloi/pictures.txt

I haven't looked at that since early summer, so I can't say I know what I did, but if you can't figure out what I did, I'd be more than happy to look back at it and help you. I believe the only problem should be mess and such, cause I never actually cleaned that code up.

Specifically, look at the following code, though it will need to be modified for your purposes:


function Thumbnails ($pics, $root, $thumbnails) {
#Pre: $pics is filled
#Post: Thumbnails are created for every new picture in directory

if ( !is_dir($thumbnails)) {
mkdir ($thumbnails);
chmod ($thumbnails, 0755);
}
else if (is_dir ($thumbnails)) {
for ($i = 0; $i < count($pics); $i++) {
if (!is_file($thumbnails . '/' . $pics[$i])) {
exec ("convert $root/$pics[$i] -resize 150x150 +profile '*' $thumbnails/$pics[$i]");
chmod ("$thumbnails/$pics[$i]", 0755);
}
}


Hope that helps.

sanddrag
10-10-2004, 01:53
In CPanel, does Fantastico have anything useful? (providing that you have CPanel and Fantastico)

ahecht
10-10-2004, 01:58
Specifically, look at the following code, though it will need to be modified for your purposes:

You ran "convert", so I assume you are using ImageMagick on your end, right?

Rickertsen2
10-10-2004, 11:33
Im working on a website right now and i made a script in php to upload an image and then display it on a different page. It works very well. My only problem is that i want to be able to turn those images into thumbnails with small file sizes automatically once i upload the file to my server. I don't really know that much php and i have no idea how i would accomplish this

Here is a snippet of code i wrote for an image gallery a while back. It has extensie debug statements that will give you som insight into its operation. It was adapted from some code i found in the PHP documentation. Note your server must have the GD library installed for this to work

function image_createThumb($src,$dest,$maxWidth,$maxHeight, $quality=100) {
print '$src = ' . $src . '<br>';
if (isset($dest)) {print '$dest is set<br>';} else {print '$dest is not set<br>';}
if (file_exists($src) && isset($dest)) {
print('JPEG Quality: ' . $quality .'<BR>');
// path info
$destInfo = pathInfo($dest);

// image src size
$srcSize = getImageSize($src);

// image dest size $destSize[0] = width, $destSize[1] = height
$srcRatio = $srcSize[0]/$srcSize[1]; // width/height ratio
$destRatio = $maxWidth/$maxHeight;
if ($destRatio > $srcRatio) {
$destSize[1] = $maxHeight;
$destSize[0] = $maxHeight*$srcRatio;
}
else {
$destSize[0] = $maxWidth;
$destSize[1] = $maxWidth/$srcRatio;
}

// path rectification
if ($destInfo['extension'] == "gif") {
$dest = substr_replace($dest, 'jpg', -3);
}

// true color image, with anti-aliasing
print '$maxHeight = ' . $maxHeight . '<br>';
print '$maxWidth = ' . $maxWidth . '<br>';
print 'src height = ' . $srcSize[1] . '<br>';
print 'src width = ' . $srcSize[0] . '<br>';
print 'dest height = ' . $destSize[1] . '<br>';
print 'dest width = ' . $destSize[0] . '<br>';
$destImage = imagecreatetruecolor($destSize[0],$destSize[1]);
imageAntiAlias($destImage,true);

// src image
switch ($srcSize[2]) {
case 1: //GIF
$srcImage = imageCreateFromGif($src);
break;

case 2: //JPEG
$srcImage = imageCreateFromJpeg($src);
break;

case 3: //PNG
$srcImage = imageCreateFromPng($src);
break;

default:
return false;
break;
}

// resampling
imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0,$destSize[0],$destSize[1],$srcSize[0],$srcSize[1]);

// generating image
switch ($srcSize[2]) {
case 1:
case 2:
imageJpeg($destImage,$dest,$quality);
break;

case 3:
imagePng($destImage,$dest);
break;
}
return true;
}
else {
print 'file does not exist<br>';
return false;

}
}

Ian W.
10-10-2004, 12:03
You ran "convert", so I assume you are using ImageMagick on your end, right?
Yes, I can't remember why I picked ImageMagick, but it works, and it's fairly easy to use.