PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm about to resize thousands of pictures using a script, so I want to make sure it's going to do it right before I go and <span style='color:blue' title='I'm naughty, are you naughty?'>smurfer</span> things up =)
<?
include 'createthumb.inc.php'; // this file resizes a picture to specivied values
/* Set up query to select all main pictures */
$result = mysql_query("SELECT username, filename FROM pictures");
/* Loop through the results and perform resizing if width OR height > 450 */
while($array = mysql_fetch_assoc($result))
{
/* Get picture dimensions */
$size = getimagesize("http://www.domain.com/uploads/".$array['username']."/".$array['filename']."");
/* Check to see if the picture NEEDS resized */
if(($size['0'] > 450) || ($size['1'] > 450))
{
/* this function's first parameter is the name of the original picture to be resized, the second paramter is the name of the resized picture */
createthumb("uploads/".$array['username']."/".$array['filename']."","uploads/".$array['username']."/".$array['filename']."",450,450);
}
}
Questions I have:
1) In the createthumb() function, will the newly resized picture overwrite (notice both parameters are the same path, same file name) the old one? If not, how can I change it so that it does overwrite the old one.
2) Have I missed anything I should be aware of before running this script on 2 gigs of pictures?
Last edited by s.dot on Tue Aug 09, 2005 8:13 pm, edited 2 times in total.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
<?
function createthumb($name,$filename,$new_w,$new_h){
global $gd2;
$system=explode(".",$name);
if (preg_match("/jpg|jpeg|JPG|JPEG|Jpg|JpG|jPG|JPg|JPEg|JPeg|Jpeg|jPEG|jpEG|jPeG|JpEg|JPEg|JpeG|jpEg|jpeG/",$system[1])){
$src_img=imagecreatefromjpeg($name);
}
if (preg_match("/png|PNG|pNg|Png|pNG|PnG/",$system[1])){
$src_img=imagecreatefrompng($name);
}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y) {
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y) {
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y) {
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$dst_img=imagecreatetruecolor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if (preg_match("/png|PNG|pNg|Png|pNG|PnG/",$system[1])){
imagepng($dst_img,$filename);
} else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
?>
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
lmao I wrote that part a LONG time ago.. should've just used a strtolower() eh?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
to be careful, of failures and such.. I'd suggest sending the files to a seperate folder.. you can always replace the existing sets with that new one later..
No, I think you're lying (says the person foreign to regex)
From what I gather, ? represents an optional character and # matches lower or upper
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
you got the ?, but # is purely a start and end marker.. it can be any symbol.. I just happen to use # because it's a bit more rare to see that in the things I'm using as a character in the pattern string..
I tested it out on one picture and it did not work. Could it be the filepermissions? Right now I have the file permissions as 644
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Don't know if that was the cause (could've been) but I also forgot to include the database connect info 8-| anywho works now. Thanks.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
include 'important.php';
include 'createthumb.inc.php'; // this file resizes a picture to specivied values
/* Set up query to select all main pictures */
$result = mysql_query("SELECT username, filename FROM pictures");
/* Loop through the results and perform resizing if width OR height > 450 */
while($array = mysql_fetch_assoc($result))
{
/* Get picture dimensions */
$size = getimagesize("http://www.showmypro.com/uploads/".$array['username']."/".$array['filename']."");
/* Check to see if the picture NEEDS resized */
if(($size['0'] > 450) || ($size['1'] > 450))
{
/* this function's first parameter is the picture to be resized, the second paramter is where to place the resized picture */
chmod("/home/scottttt/public_html/uploads/".$array['username']."/".$array['filename']."", 0777);
createthumb("uploads/".$array['username']."/".$array['filename']."","uploads/".$array['username']."/".$array['filename']."",450,450);
chmod("/home/scottttt/public_html/uploads/".$array['username']."/".$array['filename']."", 0644);
echo "done.<BR>";
}
}
echo "done";
I run this script... and it loops through it and displays a bunch of "done"s.. as I told the script to do. However, I run it again (and it shouldn't show any "done's" because the pictures should've been resized. But it goes through and does it again.
I look at the pictures and none of them are resized.
Are my CHMOD commands correct?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
The pictures are in hundreds of directories, doing that manually would be.... extremely time consuming.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.