LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-02-2004, 02:27 PM   #31
jeffreybluml
Member
 
Registered: Mar 2004
Location: Minnesota
Distribution: Fedora Core 1, Mandrake 10
Posts: 405

Original Poster
Rep: Reputation: 30

Tink.....


YOU ARE MY HERO!!!!!!!!

I did:

perl pagemaker.pl

and poof, there's my webpage!! Damn that was COOL.

Thank you, thank you, thank you.

I will TRY to affero you as soon as I can make a donation, I'm a broke dad with a single-income...

Thou art a good person. Thank you.
 
Old 11-02-2004, 03:10 PM   #32
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Heh :)

No worries. And money isn't really required,
even though I like the idea that I'm supporting
GNU and LQ via affero.

A non-financial affero is appreciated, too ...

Did you actually chmod u+x the script? I find
it weird that perl <script> works, but <script>
doesn't.


Cheers,
Tink
 
Old 11-02-2004, 03:33 PM   #33
jeffreybluml
Member
 
Registered: Mar 2004
Location: Minnesota
Distribution: Fedora Core 1, Mandrake 10
Posts: 405

Original Poster
Rep: Reputation: 30
yep, I has chmod a+x prior to tryingt it. Whatever though, I'm just glad it worked!

Thanks again,
 
Old 11-02-2004, 08:52 PM   #34
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
That is a pretty sweet program Tinkster!

I hope you don't mind, I modified it a little so it would be more generic.
# I have it setup to use row of 4 pics, either
# jpg or gif, so make sure to have a number of
# pics that is divisible by 4.
If there aren't any pics of one type or the other, you will see an error message to the effect there are no files of that type found. But it still proceeds.

# I redirect the output to index.html
# perl images.pl > index.html

Code:
#!/usr/bin/perl 
# not a perl-expert - I'm sure there's more elegant solutions :)
use strict; # enforce variable declarations and quoting

my $i;
my $j;
my $new_row = 0;
my @name=sort(`ls *.jpg *.gif`) ;
my $name1;
my $name2;

if ( (scalar @name)%4 !=0) {
    print "Wrong number of pics in directory, quitting!\n";
    exit;
}

# kudos to David_ross for suggesting the use of here-documents
print <<HEADER_EOF;
<!-- \/ starthtml -->
<html>
<head>

<style TYPE="text/css">
<!--
a:link {color:#993366;}
a:visited {color:#666666;}
a:hover {color:#FF99CC;}
--> </STYLE>

<title></title>
</head>

<body bgcolor="#1B98C2" text="#000000" link="#0000EE" vlink="#551A8B">


<table width="900" border="4" cellpadding="0" cellspacing="0" bordercolorlight="#FF99CC" bordercolordark="#993366" background="#1B98C2" bgproperties="center">

<table width="900" border="0" cellpadding="0" cellspacing="0">
HEADER_EOF

for(  $i=0; $i < (scalar @name) ; $i=$i+4){
    print "<tr height=\"270\">\n";
    for( $j=0; $j<4 ; $j++){
        chomp( $name[$i+$j] );
        $name1 = $name[$i+$j];
        $name2 = $name[$i+$j];
        $name2 =~ s/\./\.THUMB\./;
        system(`convert -size 20% $name1 -resize 20% $name2`);
        print "<td width=\"240\"><center><a href=\"$name1\"><img src=\"$name2\"></a></td>\n";
    }
    print "</tr>\n";
}


print <<FOOTER_EOF;
</table>
</td></tr></table>

</body>
</html>
FOOTER_EOF
note to self: I must learn perl
 
Old 11-02-2004, 10:01 PM   #35
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
That is a pretty sweet program Tinkster!

I hope you don't mind, I modified it a little so it would be more generic.
Heh,

thanks for the feedback, but it's actually totally trivial :)

And I just popped in and did this for Jeff to
force myself and use more perl ;)

As for the modifications: I don't think that this
script is particularly original and don't have any
claims towards the source, consider it GNU General
public licensed :D



Cheers,
Tink
 
Old 11-03-2004, 03:20 PM   #36
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Thanks Tinkster,

I've been putzing with this program and I'm not sure how to proceed with this in perl.
When I make an image gallery in konqueror, it makes a thumbs directory, converts the thumbs to png which looks like mypic.png , then it dumps them into the thumbs directory. I can get the thumbs over there ok but it ends up being something like mypic_THUMB.pnggif or mypic_THUMB.pngjpg . Having the thumbs as png is kinda handy because you don't have gif images bouncing all over the html page.

Any ideas?

Code:
#!/usr/bin/perl
# use the command: perl images.pl > index.html
# Set up in rows of 4 pics so you need an amount
# of pics that is evenly divided by 4


use strict; # enforce variable declarations and quoting

mkdir "thumbs", 0777 unless -d "thumbs";

my $i;
my $j;
my $new_row = 0;
my @name=sort(`ls *.jpg *.gif *.png`) ;
my $name1;
my $name2;

if ( (scalar @name)%4 !=0) {
   print "Wrong number of pics in directory, quitting!\n";
   exit;
}

print <<HEADER_EOF;
<!-- \/ starthtml -->
<html>
<head>

<style TYPE="text/css">
<!--
a:link {color:#FFFFFF;}
a:visited {color:#666666;}
a:hover {color:#1B98C2;}
--> </STYLE>

<title></title>
</head>

<body bgcolor="#FFFFFF" text="#000000" link="#FFFFFF" vlink="#FFFFFF">


<table align=\"center\" border="1" cellpadding="5" cellspacing="2" bordercolorlight="#FF0000" bordercolordark="#993366" background="#1B98C2" bgproperties="center">

<table align=\"center\" width=\"80%\" border="1" cellpadding="5" cellspacing="2">
HEADER_EOF

for($i=0; $i < (scalar @name) ; $i=$i+4){
    print "<tr height=\"150\">\n";
    for( $j=0; $j<4 ; $j++){
        chomp( $name[$i+$j] );
        $name1 = $name[$i+$j];
        $name2 = $name[$i+$j];
	$name2 =~ s/\./_THUMB\./;
        system(`convert -geometry x70 $name1 $name2`);
	system(`mv $name2 ./thumbs/`);
        print "<td width=\"120\"><center><a href=\"$name1\"><img src=\"./thumbs/$name2\"></a><div>$name1</div></td>\n";

    }
    print "</tr>\n";
}


print <<FOOTER_EOF;
</table>
</td></tr></table>

</body>
</html>
FOOTER_EOF

Last edited by homey; 11-05-2004 at 12:54 AM.
 
Old 11-03-2004, 04:19 PM   #37
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Have a closer look at that:

$name2 =~ s/\./_THUMB\.png/;


I'm almost certain that's where the odd names come
from in your case ;) ... specially if you re-run the script.

just do a
print "before: $name1 after: $name2 \n";
behind that statement and see ...



Cheers,
Tink
 
Old 11-03-2004, 04:37 PM   #38
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
$name2 =~ s/\./_THUMB\.png/;

That was originally $name2 =~ s/\./_THUMB\./;
this works fine with the name of mypic_THUMB.jpg or mypic_THUMB.gif
but I was kinda hoping to get the files converted to png like konqueror does.
 
Old 11-03-2004, 04:57 PM   #39
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Ummm ... convert here handles conversions from
jpg to png just dandy. The problem IS your regex.

Try this:

$name2 =~ s/\.jpg/SMALL\.png/;



Cheers,
Tink
 
Old 11-03-2004, 05:11 PM   #40
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
The problem comes from my trying to have mixed files like jpg and gif in the same directory.
$name2 =~ s/\.jpg/SMALL\.png/;
and
$name2 =~ s/\.jpg/_THUMB\.png/;

both work if you only want to do jpg files. When I use the Image gallery feature of konqueror, it converts both gif and jpg files to png and puts them in the thumbs directory.

That's why I had it like this...
$name2 =~ s/\./SMALL\.png/;
or
$name2 =~ s/\./_THUMB\.png/;

So, I wonder how to get around that problem.
 
Old 11-03-2004, 05:23 PM   #41
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
$name2 =~ s/(\.jpg|\.gif)/_THUMB\.png/;
 
Old 11-03-2004, 05:53 PM   #42
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
That converted the jpg files ok but it really got hung up on the gif file. The gif didn't go into the thumbs directory and it did put a bunch of stuff in the images directory.
I put a smaller amount of files in the images directory for testing purposes.

Here's what the images directory gets to look like.
bday3.gif
billbig.gif
bombsquad.jpg
bus.gif
bus_THUMB.png.0
bus_THUMB.png.1
bus_THUMB.png.2
bus_THUMB.png.3
bus_THUMB.png.4
bus_THUMB.png.5
bus_THUMB.png.6
bus_THUMB.png.7
cat1.jpg
cat6.jpg
images.pl
index.html
thumbs
 
Old 11-03-2004, 06:01 PM   #43
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
That's because bus.gif would be an animated
gif which there is no representation for in png?

Consequently the processed files won't be mv'ed
because their name isn't $name2, but $name2.n
as in the sequence-number of the pics in the gif.


C'mon mate, start doing your work ;) and think
about these things ...



Cheers,
Tink
 
Old 11-03-2004, 06:14 PM   #44
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Ok so I'm stupid but I wonder how konqueror does it with gifs.
 
Old 11-03-2004, 06:50 PM   #45
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
I didn't say you're stupid ... ;)

But I need to think about these things, too, I'm a
sysadmin, not a graphics or web-designer ... try
to use "convert -combine" (yes, I had to read the
man-page and experiment for ~ 20 minutes for
this piece of info) ... depending on the type of
animated gif the result may be unsightly (I've only
downloaded and converted ONE).

As for the Konqueror wondering:
a) read the source
or
b) ask on their developer list



Cheers,
Tink
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Does anyone know of a bash script can search & replace txt in a file. jimwelc Linux - Newbie 6 09-15-2008 12:13 AM
Help! Script or commanded needed to replace text in a file farmerjoe Programming 3 01-02-2005 05:59 PM
help! Script or command needed to replace text in a file. farmerjoe Linux - Newbie 2 01-02-2005 03:07 PM
Search and replace text in file using shell script? matthurne Linux - Software 2 11-02-2004 10:11 AM
trying to search and replace text file for single & multiple line breaks separately brokenfeet Programming 7 08-29-2003 01:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration