imagecopyresized()
Hey...I really have two questions:
#1- a Cron Job can be a php file right?
#2- how would i list images in a dir, move and rename them? i know that it has to do with imagecopyresized(), but I looked on php.net and i can't figure out what the attributes of it are supposed to be.
<?php
$height = 200;
$width = 136;
$pic=$HTTP_GET_VARS['pic'];
// the directory name
$handle=opendir('/home/swimtige/public_html/img/pic/');
// initialize variables
$pics=array();
$count=0;
// read directory into pics array
while (($file = readdir($handle))!==false) {
// filter for jpg, gif or png files...
if (substr($file,-4) == \".jpg\" || substr($file,-4) == \".gif\" || substr($file,-4) == \".png\" || substr($file,-4) == \".JPG\" || substr($file,-4) == \".GIF\" || substr($file,-4) == \".PNG\"){
$pics[$count] = $file;
$count++;
// don't forget to close the filter conditions here!
}
}
imagecopyresized(...); //copy to another dir, and then resize to $width and $height
closedir($handle);
?>
Mark Hensler posted this at 07:54 — 29th September 2003.
He has: 4,048 posts
Joined: Aug 2000
1 - yes...
without output...
X X X X X /usr/bin/php -f /path/to/your/image_thingy.php & 1>/dev/null/ 2>&1
X X X X X /usr/bin/wget -q -o/dev/null/ --spider /path/to/your/image_thingy.php 1>/dev/null 2>&1
X X X X X /usr/bin/lynx -source /path/to/your/image_thingy.php 1>/dev/null 2>&1
with output...
X X X X X /usr/bin/php -f /path/to/your/image_thingy.php
X X X X X /usr/bin/wget -q -O- -o/dev/null /path/to/your/image_thingy.php
X X X X X /usr/bin/lynx -dump /path/to/your/image_thingy.php
2 - Never used it. (dont have time to research, atm)
Mark Hensler
If there is no answer on Google, then there is no question.
kb posted this at 01:34 — 30th September 2003.
He has: 1,380 posts
Joined: Feb 2002
ok thanks.
Suzanne posted this at 12:00 — 30th September 2003.
She has: 5,507 posts
Joined: Feb 2000
Have you read through the comments on that function? They seem quite complete. The image is resized, THEN copied, though. It's resized in memory, then stored in a new location.
What have you tried?
m3rajk posted this at 17:18 — 1st October 2003.
They have: 461 posts
Joined: Jul 2003
if i remember correctly first you need to read in the image, then figure out how much of it you want to resize...
ImageCopyResize($imageSource, $beginingXcoordinate, $beginingYcoordinate, $endingXcoordinate, $endingYcoordinate, $newMaxX, $newMaxY);
meaning that $imageSource is the source you read in, and the rest should be self explanatory.
like i said, i've done this before (but not as a cron job). gimme a sec, i'll post an example
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
m3rajk posted this at 17:26 — 1st October 2003.
They have: 461 posts
Joined: Jul 2003
example (reformatting of something i have that works...$pic is the image (full path) and set previously... this gets sent to the browser, you'll have to adapt to something else).
also note that the sizes here are in pixels, so that's putting out a 300 by 300 pixel image
<?php
$src=ImageCreateFromJPEG($pic); # image read in
$width=ImageSx($src); # width (max x coord) of image
$height=ImageSy($src); # height (max y coord) of image
$x=300; # new max x coord
$y=300; # new max y coord
$dst=ImageCreate($x,$y); # create a blank image for resize to send to
ImageCopyResized($dst,$src,0,0,0,0,$x,$y,$width,$height); # resize
header('Content-Type: image/png'); ImagePNG($dst); # send to browser
?>
umm.. update of what i thought (correct this time)
ImageCopyResize($destinationImage, $imageSource, $beginingDestXcoordinate, $beginingDestYcoordinate, $beginingSrcXcoordinate, $beginingSrcYcoordinate, $endingDestXcoordinate, $endingDestYcoordinate, $endingSrcXcoordinate, $endingSrcYcoordinate);
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
kb posted this at 00:45 — 2nd October 2003.
He has: 1,380 posts
Joined: Feb 2002
Great! Thanks.
m3rajk posted this at 19:53 — 2nd October 2003.
They have: 461 posts
Joined: Jul 2003
np.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.