Robbie's Scripting

Started by RobbieThe1st, June 06, 2007, 04:49:50 AM

Previous topic - Next topic

RobbieThe1st

I love Scripting and automating things! Here are a few scripts of mine. All of the scripts posted here are PHP scripts, atleast for now. Also, this stuff is creative work, so thats why its here.
Note: All of these scripts are *NOT* final versions, or even released really. I built them for my own use, and then, adapted them to be usable for other people. There is *no* documentation, and the instructions I posted here I wrote as I was posting this.

I have released the comicgrabber-pack to a few friends, and walked them through it on IRC or MSN, so if you need my help, post or pm me.

** Disclaimer **
All scripts are posted for informational use only - If you get into trouble using them, its not my fault. Dont sue me :<


A NOTE: To save Amber's bandwidth, do not run the DMFA comic-grabber, atleast not until after you have downloaded the complete archive  One large ZIP(orig versions): http://robbiethe1st.ktserv.com/dmfa_chapters/all.zip Chapter-CBZ(with text): http://robbiethe1st.ktserv.com/dmfa_chapters/ (all files but all.zip), Individual JPEG files: http://robbiethe1st.ktserv.com/dmfa/
Um, a note: if you choose to download the with-text version only, you have to rename them to .jpg(or make 769 blank Vol001-Vol769.jpg files), before you run the dmfa comic-grab script. the files need to be in /comics/dmfa.


First up:
Comic-grabber and Comic-keep-up-to-date-er. This script has everything included(including a bare-bones copy of php), just extract to any folder, set it up, and run it.
http://robbiethe1st.ktserv.com/downloads/everything_6-6-07.rar
Basically, this script-set, once properly setup, can: A. grab all the archives of any comic which its setup for(like DMFA *whistles*), B. keep that local archive up to date, and C. add the updates to its cache folder as well as the archive, so you can, once in a while, look in the cache folder for new comics, then delete em from there once you have read them. Also, for people who know php, I have added another function: after the download of a new comic, it can be configured to run a special script, for example to modify said comic.
Instructions for use:
Comic-keep-updated script -
go into your /comics/current/includes folder, and move the .inc files for the comics you want into the /comics/current/comics folder. now, run /comics/update.bat.
If you want to, you can either manually launch the update.bat file, or schedule it as a task.
Special-addon: simply put your script in the /comics/current/alt folder with the same name as the comic you want t to be triggered by - so if the comic is /comics/current/comics/dmfa.inc, the script name would be /comics/current/alt/dmfa.inc
I have provided a sample script in the /comics/current/alt-unused folder(said sample script will, on download of a new DMFA comic, download the comic's text-string and stick it on the bottom of the comic, which it will stick in the /comics/dmfa/with_text folder. It will then take a copy of the version with text, remove white-space from the edges, and resize it, to either 400,600,or 800 height and a max of 837 width(those numbers are editable)).

Comicgrabber:
First, run index.bat, press 1, then type in the 3-number combination for the comic you want. It will then start downloading said comic.

Comic-requests: Post all new comic requests here in this topic, or PM me on any service I have(check my profile).

Oh yea, if anyone can find/make me a better interface, it would be appreciated - once i have that, I can make it better.


Other scripts:
These scripts require apache and php to be installed on your local computer - Use a program like EasyPHP for windows.

1. DMFA Quote-Grabber:
<?php
set_time_limit
(0);
$basedir "./"
$fopen fopen("quotes.txt","a");
for(
$i=1$i<790$i++) {
$ii str_pad($i,3,"0",STR_PAD_LEFT);
echo "quote ".$ii." starting.<br>\n";
$ch curl_init("http://www.missmab.com/Comics/Vol_".$ii.".php");
curl_setopt($chCURLOPT_REFERER,"http://www.missmab.com");
curl_setopt($chCURLOPT_VERBOSE,0);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($chCURLOPT_RETURNTRANSFER1);
$data curl_exec($ch); curl_close ($ch);
$data1 explode("<I>",$data);
$quote explode("</I>",$data1[1]);
$aquote $quote[0];
$finaltext $ii." ".$aquote;
fwrite($fopen,$finaltext."\n"); 
};
fclose($fopen);
?>

2. DMFA Bulk Text-adder(reqs: Quotes, Dmfa-Archives)

<?php
$file 
file("dmfa_quotes.txt");
for(
$i=0$i<count($file); $i++) {
$file[$i] = trim($file[$i]);
$num substr($file[$i],0,3);
$quote substr($file[$i],3,strlen($file[$i]));
if(file_exists("./dmfaresize/Vol".$num.".png")) { } else {
  
$bg imagecreatefromjpeg("./dmfa/Vol".$num.".jpg");
  
$imagex imagesx($bg); //width 
$imagey imagesy($bg); //height
$box imageftbbox(12,0,"../common/arial.ttf",$quote);
$width = (($imagex abs($box[4] - $box[0])) / 2); 
$height $imagey 12;
$image imagecreatetruecolor($imagex,$imagey+15);
$textcolor imagecolorallocate($image,0,0,0);
$white imagecolorallocate($image,255,255,255);
imagefilledrectangle($image,0,0,$imagex,$imagey+14,$white);
imagecopy($image,$bg,0,0,0,0,$imagex,$imagey);
imagettftext($image,12,0,$width,$height,$textcolor,"../common/arial.ttf",$quote);
imagepng($image,"./dmfaresize/Vol".$num.".png");
echo "Vol".$num." completed.<br>\n";
};
};
?>

3. Printer-Page Maker: http://robbiethe1st.ktserv.com/downloads/printer-page_maker.rar
This script makes page of comics, auto-lining them up, for printing purposes. The comics should be resized, with a max-width of 837, or else it probly wont print correctly(it will overlap borders). It makes 2 sets of pages: A and B. You want to print the A one, then flip over the page to the back, and print the B one. Once that is complete, simply fold the  8.5X11 page in half along the line, making a 5.5X8.5 page X 2. Now simply use a 3-hole-punch on it, cut it in 2,  and stick it in one of those medium-height 3-ring-binders.


4. Image-Resizer:
<?php
set_time_limit
(0);
for(
$i=1$i<101$i++) {
$name "Vol".str_pad($i,3,"0",STR_PAD_LEFT).".png";
$width 837;
$imagein imagecreatefromstring(file_get_contents("./cleaned/".$name));
$imagex imagesx($imagein); $imagey imagesy($imagein);
//find max height
$ratio $imagex $imagey;
if(
1.60 $ratio) { 
$maxheight 400;
} else if(
$ratio) {
$maxheight 600;
} else {
$maxheight 800;
};
//find width/height
if(floor($ratio $maxheight) <= $width) {
$outw floor($ratio $maxheight);
$outh $maxheight;
} else {
$outw $width;
$outh floor($width $ratio);
};
//resize & save image
$image imagecreatetruecolor($outw,$outh);
imagecopyresampled($image,$imagein,0,0,0,0,$outw,$outh,$imagex,$imagey);
imagepng($image,"./resized/".$name);
echo "image ".$i." complete<br>\n";
};
?>

This is currently set for resizing sets of dmfa comics, but can be modified for other uses.
For a more user-friendly resizer, get Irfan View.


5. Image-cleaner:

<?php
set_time_limit
(0);
for(
$i=1$i<101$i++) {
$name "Vol".str_pad($i,3,"0",STR_PAD_LEFT);
$imagein imagecreatefromstring(file_get_contents("./".$name.".png"));
$imagex imagesx($imagein); $imagey imagesy($imagein);
$threshold 100;

$chopt 0;
for($y=0$y<ceil($imagey 2); $y++) {
$clean true;
for($x=0$x<$imagex$x++) {
$pixcolor imagecolorsforindex($imagein,ImageColorAt($imagein,$x,$y));
if($threshold $pixcolor['red'] && $threshold $pixcolor['green'] && $threshold $pixcolor['blue']) {
} else {
$clean false;
};
};
if($clean == true) {
$chopt $y 1;
} else {
$y ceil($imagey 2);
};
};
$chopl 0;
for($x=0$x<ceil($imagex 2); $x++) {
$clean true;
for($y=0$y<$imagey$y++) {
$pixcolor imagecolorsforindex($imagein,ImageColorAt($imagein,$x,$y));
if($threshold $pixcolor['red'] && $threshold $pixcolor['green'] && $threshold $pixcolor['blue']) {
} else {
$clean false;
};
};
if($clean == true) {
$chopl $x 1;
} else {
$x ceil($imagex 2);
};
};
$chopr $imagex;
for($x=$imagex 1$x>ceil($imagex 2); $x--) {//<
$clean true;
for($y=0$y<$imagey$y++) {
$pixcolor imagecolorsforindex($imagein,ImageColorAt($imagein,$x,$y));
if($threshold $pixcolor['red'] && $threshold $pixcolor['green'] && $threshold $pixcolor['blue']) {
} else {
$clean false;
};
};
if($clean == true) {
$chopr $x 1;
//echo $x."clean ";
} else {
$x 0;
};
};
$chopb $imagey;
for($y=$imagey 1$y>ceil($imagey 2); $y--) {//<
$clean true;
for($x=0$x<$imagex$x++) {
$pixcolor imagecolorsforindex($imagein,ImageColorAt($imagein,$x,$y));
if($threshold $pixcolor['red'] && $threshold $pixcolor['green'] && $threshold $pixcolor['blue']) {
} else {
$clean false;
};
};
if($clean == true) {
$chopb $y 1;
} else {
$y 0;
};
};
//echo $chopb;
$image imagecreatetruecolor($chopr $chopl,$chopb $chopt);
imagecopy($image,$imagein,0,0,$chopl,$chopt,$chopr $chopl,$chopb $chopt);
//header('Content-Type: image/png');
imagepng($image,"./cleaned/".$name.".png");
echo "image ".$i." complete<br>\n";
};
?>

This script strips white-space off an image. Currently set for DMFA comics, but can be uses for other purposes as well.


I hope I dont get in too much trouble for this, but... Information is meant to be free!!!!

If you have any questions, just ask me!

-RobbieThe1st

Pasteris.ttf <- Pasteris is the font used for text in DMFA.

llearch n'n'daCorna

I suspect "if someone wants the output of these, I can supply a copy of the cache soas not to flatten Amber's server and give her a huge bandwidth bill" type thing might be a good idea.

Either that or donating a sum of money to Amber for said bill...
Thanks for all the images | Unofficial DMFA IRC server
"We found Scientology!" -- The Bad Idea Bears

RobbieThe1st

Quote from: llearch n'n'daCorna on June 06, 2007, 05:48:00 AM
I suspect "if someone wants the output of these, I can supply a copy of the cache soas not to flatten Amber's server and give her a huge bandwidth bill" type thing might be a good idea.

Either that or donating a sum of money to Amber for said bill...
Well, honestly, only the one section of one script downloads DMFA, and the update-checker actually takes less bandwidth than manual checking. All of the other scripts work upon already DL'ed comics.
I also have a cache ready and bandwidth, but if you recall ages ago, upon the topic I posted when I joined, amber said she might make an anniversary CD, and well, noone wanted me to show the archives in cbz form.

Also, dling a comics archive takes a bit less bandwidth than going through them from the web - no other images/text to download.

-Robbie

Pasteris.ttf <- Pasteris is the font used for text in DMFA.

llearch n'n'daCorna

All true, but generating an offline archive makes a big spike - simply because the machine processing it doesn't have to display anything, it just has to download lots.

It's a politeness to Amber thing, really. You're providing a script that will enable a large group of fans to get a complete copy of the archive, relatively easily. That's a lot easier for them than making their own.

Now me, I have an archive already, because I save a copy of each days' strip when I view it, in order to update the radio scripts. But think just how much bandwidth would be eaten if, say, 20 people (not unreasonable with the folks we have here, I'd say) looked at this script, downloaded, and ran it. I make it something on the order of 90Mb each. That's a -big- wedge of bandwidth, you have to agree.


I'm happy to assist with something like torrenting it, soas to spread the bandwidth around; heck, I don't pay for bandwidth, so I'm happy to host it, even though I've only got 512k upstream here. I just think handing Amber a 90Mb download and sucking it off her repeatedly is probably something that should be avoided, at least unless you ask her nicely if she minds.

After all, she's the one paying to host the server.
Thanks for all the images | Unofficial DMFA IRC server
"We found Scientology!" -- The Bad Idea Bears

RobbieThe1st

#4
Quote from: llearch n'n'daCorna on June 06, 2007, 06:09:43 AM
All true, but generating an offline archive makes a big spike - simply because the machine processing it doesn't have to display anything, it just has to download lots.

It's a politeness to Amber thing, really. You're providing a script that will enable a large group of fans to get a complete copy of the archive, relatively easily. That's a lot easier for them than making their own.

Now me, I have an archive already, because I save a copy of each days' strip when I view it, in order to update the radio scripts. But think just how much bandwidth would be eaten if, say, 20 people (not unreasonable with the folks we have here, I'd say) looked at this script, downloaded, and ran it. I make it something on the order of 90Mb each. That's a -big- wedge of bandwidth, you have to agree.


I'm happy to assist with something like torrenting it, soas to spread the bandwidth around; heck, I don't pay for bandwidth, so I'm happy to host it, even though I've only got 512k upstream here. I just think handing Amber a 90Mb download and sucking it off her repeatedly is probably something that should be avoided, at least unless you ask her nicely if she minds.

After all, she's the one paying to host the server.
Well, I'm taking this as "noone minds if i make a big zip of em all for everyone". Also, the spike wont be quite as big as you say, atleast it wont overload the server I dont think, as it loads them pretty slowly - test it out. For me, the rate is about 1 every 5 seconds, MAX - larger comics take longer.

Here you go: http://robbiethe1st.ktserv.com/dmfa_chapters/all.zip up to 769 which was when I joined this forum.

Pasteris.ttf <- Pasteris is the font used for text in DMFA.