Development

Wanted (source)code plugin for Wordpress

The past days I’ve been posting stories with a few code samples – Perl, PHP, Javasscript and/or HTML. While Wordpress is fantastic to a number of things, handling sourcecode examples in the posts, reallly isn’t one of them. I’ve been playing with a number of plugins, but none of them really works for me. What I’m looking for is this: It must be able to handle HTML, Javasscript, PHP and Perl sourcecode.

Changing a form submit url with javascript

Sometimes you might need to change the address a form submits to, it’s quite easy with javascript. One example could be if you - like me - from time to time is hit hard by comment-spammers. Changing the submit URL on the form with javascript, makes it at least somewhat harder for “automated brainless robots” to kill your site in a spam attack. The recipie below is a very simple example, but so far it seems to work quite well: <script type="text/javascript"> function doSubmit() { var target1 = 'hello'; var target2 = 'world'; var target3 = '.

Bulk resizing images with Perl

Suppose you’ve just filled you digital camera with an endless stream of photos. You want to place them online at your website, but placing 5+ megapixel files online, well…probably a bad idea. Let’s resize them to a propper size - and why not use Perl and ImageMagick for the job. Not a problem, here’s a complete example on how to resize all images in a directory . Make sure you have ImageMagick installed.

Syntax checking PHP on the commandline

I’m sure most people only thing of PHP as a Weblanguage due to be called through a browser. It has however since version 4.3.0 also been possible to use PHP on the commandline - as you do with Perl, Shell scripts and likewise. If you’re using Linux (or an other Unix-like operating system - including Mac OSX) you probably have a few small programs available which can make it a breeze to check if the syntax in all you PHP scripts is correct.

Converting between image formats with Perl

Changing files from one format to another is quite easy with a little bit of ImageMagick . In the example below a JPG image (test.jpg) is converted into a GIF-image (test.gif). To output in a different (ImageMagick supported ) format, just change the “image->Set” line. #!/usr/bin/perl -w use strict; use Image::Magick; my $image = Image::Magick->new(); # To explicitly set image format use this instead: # my $image = Image::Magick->new(magick=> 'JPEG'); my $x = $image->Read('test.