View Full Version : Cron Job for Image Scaler and Convert Image
big-dog1965
01-22-2007, 12:56 AM
Is there a way to create a Cron Job that will scale all images in a folder.
I would like it to run like once a week or so.
Also is there a way to have a Cron job to Convert Image Format in a folder.
areidmtm
01-22-2007, 09:11 AM
Yes, but you shouldn't be having the server do that. That will be taking too much recourses and slow down the sever and everyone on it. Eventually you will get a CPU error.
It's better to resize them on your computer then upload them. You can also use cPanel do that that.
cPanel >> Image Manager
big-dog1965
01-22-2007, 11:30 AM
I have a assistant that helps with pictures and tends to upload pics that are to large. He does not have cp access. and cant seem to resize on his pc. My thought was if the cron would do it, then the pic size would be smaller in bytes and also look right on the webpage. I tried a php script thinking if a gallery type app does it I should be able to do it. With out knowing php I can seem to get it to work right.
Any ideas on how to do this another way, short of getting a new assistant.:)
I want to resize the pics to 177px x what ever. keeping aspect ratio on pic.
bobdog
01-22-2007, 11:36 AM
Aside from buying a graphics program like Photoshop or JASC Paint Shop Pro, you could try Gimp. It's free:
http://www.gimp.org/
areidmtm
01-22-2007, 11:40 AM
http://www.irfanview.com/ is free and will do batch resizing
big-dog1965
01-22-2007, 11:47 AM
He doesnt know computers at all, to have him mod a pic would be like pulling teeth. I can already see it, the pics would be all jacked up and the reply would be oh I over wrote the org. oops! time and time again.
areidmtm
01-22-2007, 12:25 PM
Irfanview is really easy. It's as easy as uploading the pictures. All you do is open the program, press the 'B' key on the keyboard, drag all the pictures over, tell it where to put the resized pictures and convert it.
Once the settings are in place, it remembers them. It's really easy. My wife can do it! :D
big-dog1965
01-22-2007, 07:34 PM
will imagemagick work some how to do this resizing i need done
if yes how might i set that up
areidmtm
01-22-2007, 09:03 PM
Yes you can, but like i said before, you should not be having the server do this. It's only going to cause the box to have a lot of unnecessary load on it and slow down everyone. You will get CPU errors and your account will be suspended.
big-dog1965
01-22-2007, 09:33 PM
Not to sound stupid, but how does a gallery not put the same type of load on it. the gallery that I had did some picture resizing and thumbnails and stuff like that. Thats what got me thinking that this could be done it just would be done on a directory of 40 images insted of who know how many.
bobdog
01-22-2007, 09:55 PM
Run it on your local drive (your computer) then upload.
Trying to make a cron job or getting the server to do it for you is overkill. Just resize the images on your computer before uploading.
It's so easy a CAVEMAN could do it. (giggle-think Geico ads)
http://www.sirenedesigns.com/pictures/caveman.jpg
areidmtm
01-22-2007, 10:23 PM
Not to sound stupid, but how does a gallery not put the same type of load on it. the gallery that I had did some picture resizing and thumbnails and stuff like that. Thats what got me thinking that this could be done it just would be done on a directory of 40 images insted of who know how many.
Those gallery scripts put a HUGE load on the server. People with a lot of images will get CPU errors and get suspended.
I'm telling you, just do them on your computer and then upload them. It's faster, it's easier and a lot better one the server and everyone else's account. Or go ahead and make the server do it and slow down the box and get suspended for CPU errors. You apparently really don't want my help because you're not accepting the facts and what I am saying.
big-dog1965
01-22-2007, 11:04 PM
Its not that, Im just trying to learn. I dont learn if I dont ask question. and see excample.
Sorry if I afend with my questions.
Im not the one that uploads the images and the one that does cant. As with everyone else that uses bluehost I want the service to be fast and reliable.
That sparks another question if Im allowed x amount of bandwidth and am not maxxing that out by no means am I putting a load on the server or does bandwidth have anything to do with that.
death2all
01-23-2007, 12:28 AM
If with your cron you make sure that you don't attempt to re-resize the same images week after week (thus increasing the load with each passing week) by using some sort of flag for each image in a database then you can use something like this: http://gr.php.net/manual/en/function.getimagesize.php#52099 and changing the last ImageJpeg($dst); to ImageJpeg( $dst, $destination_file);
areidmtm
01-23-2007, 09:35 AM
if Im allowed x amount of bandwidth and am not maxxing that out by no means am I putting a load on the server or does bandwidth have anything to do with that.
Yes, bandwidth and the server load are different things.
Sorry to be up tight, but I have told you the same thing 3 times. :rolleyes:
big-dog1965
01-23-2007, 05:54 PM
Is there a way in a upload.php or .shtml page to check the file dimisions before upload and if the width isnt 177px in width have it error saying something like resize to 177px
bobdog
01-23-2007, 10:19 PM
OK, that's it. I'm going off... :eek:
You are talking about writing php or shtml and you can't even resize a picture?
Are you pulling my chain here?
Giggle... :p RESIZE THE PICTURE BEFORE UPLOADING.
HELLO? IS THIS THING WORKING? CAN YOU HEAR ME?
We have given you several options. Some are free. So easy the family dog could walk up to the keyboard and do it.
If your assistant can't do this, or you can't train this person on how to do it, put down the mouse and slowly back away from the computer. ;)
areidmtm
01-23-2007, 11:38 PM
Is there a way in a upload.php or .shtml page to check the file dimisions before upload and if the width isnt 177px in width have it error saying something like resize to 177px
You can, but yes it would be quite a bit of scripting.
big-dog1965
01-23-2007, 11:39 PM
I have posed several questions in this thread.
Here it is in a nut shell.
I would like to automate the procedure for resizing an image file (from what ever it is to 177 x _ (aspect ratio)) with a cron job. I understand that is an overload on server (don’t really but). So I figured if my upload.php file can upload the file why cant it also look at the file and if it is bigger than 177 x what ever return a message that say resize image to 177 x _ and try again.
This shouldn’t load the server because it’s not using a cron job or resizing the image, but instead displaying a message to user on the upload.php page. I can paste the php file if someone knows php and can help.
It’s my turn Dog:(
I never claimed to be a programmer if that were the case I wouldn’t be on here asking for help. I am very proficient at Photoshop and 3D programs but I’ am trying to make this so someone else can do it so I don’t have to. If you don’t know how to help me simply don’t post a reply on this topic, and I will assume there is no help or a lack of on this forum and move on. I’ve been satisfied with Blue host web service but I must say the forum is a bust if all I get is grief because I ask questions.
areidmtm
01-23-2007, 11:41 PM
I’ve been satisfied with Blue host web service but I must say the forum is a bust if all I get is grief because I ask questions.
Remember this is a USER TO USER forum. Bluehost employees do not come here. We are all users just like you.
Maggilove
01-24-2007, 12:19 AM
...I’ am trying to make this so someone else can do it so I don’t have to...
I have to agree with the guys here... you should do your man a big favour and introduce him to IrfanView. It really is very, very simple... I have pointed many a technoklutz in that direction, and all have grasped it in minutes... and in many cases it has given them the confidence to go on to learn other things.
big-dog1965
01-24-2007, 12:37 AM
I agree as well. I decided the alert message was maybe the way to go because of the load thing.
I have seen it time and time again buy book send them to school and they still dont resize:)
Atleast the alert message would stop the image or at least make him remember to resize it. the program to resize isnt the problem. Simply the brain freeze at upload to resize.
magpie2419
01-24-2007, 01:41 AM
Can you not set a parameter in your gallery or whatever you use, that will only allow uploads of a certain size or dimension, this would stop the upload till it is the correct size or dimension.
Just a thought....;)
big-dog1965
01-24-2007, 01:49 AM
Heres the upload.php file that I use to upload with
<html>
<head><title>popular</title></head>
<body bgcolor="FFFFCC" style="margin: 1px">
<table border="1" cellpadding="5" width="100%" align="center">
<tr><td colspan="2" bgcolor="#0066cc"><font color="#FFFFCC" size="+1" align="center">Files Uploaded</font></td></tr>
<tr bgcolor="#ffff00"><td><nobr>File Name</nobr></td>
<td align="right"><nobr>File size</nobr></td></tr>
<?
/*
* SET THE SAVE PATH by editing the line below. Make sure that the path
* name ends with the correct file system path separator ('/' in linux and
* '\\' in windows servers (eg "c:\\temp\\uploads\\" )
*/
$save_path="/path/to/web/site/file/uploads/popular/";
$file = $_FILES['userfile'];
$k = count($file['name']);
for($i=0 ; $i < $k ; $i++)
{
if($i %2)
{
echo '<tr bgcolor="#FFFF99"> ';
}
else
{
echo '<tr>';
}
echo '<td align="left">' . $file['name'][$i] ."</td>\n";
echo '<td align="right">' . $file['size'][$i] ."</td></tr>\n";
if(isset($save_path) && $save_path!="")
{
$name = split('/',$file['name'][$i]);
move_uploaded_file($file['tmp_name'][$i], $save_path . $name[count($name)-1]);
}
}
echo "<tr style='color: #0066cc'><td>SSL</td><td>". (($_SERVER[HTTPS] != 'on') ? 'Off' : 'On') ."</td></tr>";
if(! isset($save_path) || $save_path =="")
{
echo '<tr style="color: #0066cc"><td colspan=2 align="left">Files have not been saved, please edit upload.php to match your configuration</td></tr>';
}
?>
</table>
<p> </p>
</body>
</html>
death2all
01-24-2007, 03:11 AM
list($width, $height, $type, $attr) = getimagesize($file_in);
$new_width = $width;
$new_height = $height;
if ($width > 177)
{
$relation = ($height/$width);
$new_width = 177;
$new_height = ceil($new_height * $relation);
}
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($file_in);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_p, $file_out, 100);
In the above $file_in is the input filename and $file_out the output filename ($file_id should propably be sth like $_FILES[...]).
Also it only works if the input file is jpg.
benornoel
03-22-2007, 04:39 PM
I understand the issue of the load on the server, but a web administrator should not have all the burden of resizing when it comes to a content management system, nor does the burden need to lie on the users (in my case, baby boomers who even have trouble uploading an image).
I know that there is server-side reimaging in the BlueHost cPanel (the Image Manager under Web Server Config). Is there any way to automate that resizing process? I would only be doing it for a small amount of pictures. I could set it up so I get an email anytime someone uploads an image, but I want the resizing to be instant.
I could install a program like Imagemagick, but I was just wondering if the preexissting Image Manager resizing function was available as a command I could put somewhere in my PHP uploading file.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.