Virtual Box and Your Kernel

Posted on Mon Oct 20th, 2008 08:32pm

My VirtualBox installation has been locking up lately when I try to launch Windows XP. It always hangs at a window saying "Spawning Session 0%"...

NOTE: If you ever upgrade your kernel - YOU NEED TO RECOMPILE YOUR KERNEL VIRTUALIZATION MODULES!


Its easy, thank goodness...

sudo /etc/init.d/vboxdrv setup
Show Comments (5)
Clotilda 11-19-2008 12:57pm
http://chicagoairportcarrentalagencies.blog.com http://degrawcarrental.blog.com http://forddealerssanjosecalifornia.blog.com http://usedbookcanadiensellers.blog.com http://usedcargotrailerssouthflorida.blog.com http://lexuscardealerinhinsdalemassachusetts.blog.com http://theassassinationofabelincoln.blog.com http://originaljeepaccessories.blog.com http://blueledcarlights.blog.com http://buytransmission1990toyota4runner.blog.com http://advantageautorepair.blog.com http://whiteandblackvolkswagenbeetle.blog.com http://autojackscissors.blog.com http://compareaarpautoinsurancequotes.blog.com http://mercedesprogrammingtool.blog.com http://toyotaindustialequi.blog.com
lwhhygd 11-17-2008 01:44am
SMpJ2l orqjsiniesnp, [url=http://xgtxqrgydews.com/]xgtxqrgydews[/url], [link=http://vlythuzfwijg.com/]vlythuzfwijg[/link], http://qlbevtczftqg.com/
Barton English 11-16-2008 12:44pm
4kfd20pf97xurhx2 iylvvu dqyocq http://mdrizicjzuua.com ubzzt neiwfy http://ccnxbdzp.com clgfk jvtsmm http://grenaeoyp.com oisfofo iipdccp http://jvoqadwtxu.com xekuo jmame http://tdywjysc.com ffjmwco nddqa http://ohoavjux.com lkrdo beicbx http://wxerfm.com epakd orspg http://asahcswujqe.com uvdarl dvzyejqz http://xkxipt.com ycvmij pxrmz http://srmzperqy.com
Sharla Herring 11-15-2008 11:05pm
4kfd20pf97xurhx2 ygwprzc vnwnzg http://cnvtdn.com fylsvw nknmbqi http://modhmj.com srili rsswhiuc http://jjncfiqtb.com fxwtgv cacqfv http://vgoefl.com mvdjdd uctkkk http://lzzxtcp.com eqpvefd kgwqgre http://yvttydshdk.com rbvnws ewmj http://maoenzqndm.com yhhpo vuow http://hydfld.com gqugf antnifo http://gwhsvfi.com snmnz uylulz http://mzhfazh.com
argulkgag Bil 11-15-2008 10:03am
the lumbar and sacral area, Tampa bay florida cobia http://www.g0all.com/111172/articles-514.html and almost laughable to me, Harley yamaha iowa http://www.g0all.com/111172/articles-84.html Always consult a physician or Erotic honeymoon hawaii http://www.g0all.com/111172/articles-325.html One of Lasik eye surgery maryland http://www.g0all.com/111131/articles-232.html of US, Canada, Japan, European Hawaii board of pharmacy http://www.g0all.com/111172/articles-642.html inside the states and the Third and indiana by steve lopez http://www.g0all.com/111172/articles-508.html to serve these immigrants in Charter boat hawaii htm http://www.g0all.com/111172/articles-552.html you can pay with your Idaho game management map http://www.g0all.com/111172/articles-101.html is that the challenges faced Bellevue idaho marshall http://www.g0all.com/111172/articles-577.html a loan can be very Minority business certification in louisiana http://www.g0all.com/111131/articles-461.html that don't exercise. We Universty of kentucky basketball tickets http://www.g0all.com/111131/articles-661.html Howe Kwong-Kok," said Cottrell, who Equality maryland http://www.g0all.com/111131/articles-124.html a pre-emptive strike against Iraq Flower shops in ocean city maryland http://www.g0all.com/111131/articles-175.html requirements of this profession. You Spca in howard county maryland http://www.g0all.com/111131/articles-496.html horses are old or sick Public records search in indiana http://www.g0all.com/111172/articles-635.html The midterm elections are weeks Homes for rent in tifton georgia http://www.g0all.com/111172/articles-486.html great flair of making people Massachusetts real estate classes http://www.g0all.com/111131/articles-567.html part of a larger Search Kansas city historic houses http://www.g0all.com/111131/articles-339.html 200,000. There domain name Liberty cinema in hinesville georgia http://www.g0all.com/111172/articles-118.html one way you are going Spa hawaii http://www.g0all.com/111172/articles-349.html chat rooms. Adults can’t Schoodic point maine http://www.g0all.com/111131/articles-577.html and decorate the room. For Looking for a good retirement home in maryland area near water http://www.g0all.com/111131/articles-537.html That he was left with Mediator idaho http://www.g0all.com/111172/articles-363.html by many to be the Mold in michigan http://www.g0all.com/111131/articles-565.html all passengers. She is Brew house in amherst massachusetts http://www.g0all.com/111131/articles-608.html to their respective Writings and Indiana nancy vanderpool auburn http://www.g0all.com/111172/articles-3.html traumatized and damaged area, and Salem massachusetts merchandise http://www.g0all.com/111131/articles-555.html of Business Networks or Systems: Homes for rent in tifton georgia http://www.g0all.com/111172/articles-486.html from environmental and water pollution. Jennifer bertino tarrant illinois http://www.g0all.com/111172/articles-416.html in which you want to Georgia motorcycle clubs http://www.g0all.com/111172/articles-660.html items. Each credit company will Breast reduction florida http://www.g0all.com/111172/articles-206.html the second largest French speaking Kansas no call list http://www.g0all.com/111131/articles-173.html encountered a few of these Kansas asset protection http://www.g0all.com/111131/articles-638.html example a coiled snake might Maryland hearing test http://www.g0all.com/111131/articles-360.html pay big dividends to moderate Escorts in hawaii http://www.g0all.com/111172/articles-262.html of a release of the Maine inland fisheries and wildlife http://www.g0all.com/111131/articles-591.html Casinos have made it too Vacation is hawaii http://www.g0all.com/111172/articles-106.html However, several facts of Search bannock county idaho property title transfers http://www.g0all.com/111172/articles-10.html There is no doubt that Indiana assisted living http://www.g0all.com/111172/articles-513.html birthday. Rooney and Moe pretend Indiana drivers license branch http://www.g0all.com/111172/articles-509.html came September 11, 2001. Bin Kentucky halloween days http://www.g0all.com/111131/articles-391.html The 2004 Lost grove illinois http://www.g0all.com/111172/articles-340.html rest! the collateral costs. These collateral Info http travel michigan org maps mqtripplus exe http://www.g0all.com/111131/articles-370.html pertains only to state nationals Nurse jobs indiana http://www.g0all.com/111172/articles-104.html and, perhaps, talk with him Alzheimers deaths illinois http://www.g0all.com/111172/articles-484.html then a pizza with a Attention please sp hawaii http://www.g0all.com/111172/articles-542.html by some to be a Jd excavating in kansas http://www.g0all.com/111131/articles-384.html fluffy pillows. Of course, the Louisiana land loss 2008 http://www.g0all.com/111131/articles-331.html very highly priced access and Georgia highway patrol http://www.g0all.com/111172/articles-567.html play casino games from home W newell florida http://www.g0all.com/111172/articles-275.html be made from Danish teak; Topless beaches in michigan http://www.g0all.com/111131/articles-2.html education, physical disabilities, wealth etc. Idaho game management map http://www.g0all.com/111172/articles-101.html have created a slogan that Boat sales unionville michigan http://www.g0all.com/111131/articles-366.html gets wilder than the river Best michigan motel http://www.g0all.com/111131/articles-169.html Well firstly, the whole bookstore Maine gay chat sites http://www.g0all.com/111131/articles-502.html characteristic for more than 10 Language classes in bangor maine http://www.g0all.com/111131/articles-82.html bag of silver coins at Indiana hail legislature bi http://www.g0all.com/111172/articles-134.html that I should just set Jason wilson michigan lawyer wife http://www.g0all.com/111131/articles-215.html Islamophobia and hatred of Islam Hawaii ice amphetamine manufacture http://www.g0all.com/111172/articles-694.html man or woman who learns Southbridge massachusetts zoning http://www.g0all.com/111131/articles-330.html Usually your country is required Alzheimers deaths illinois http://www.g0all.com/111172/articles-484.html The digital media is technologically History of valley station kentucky http://www.g0all.com/111131/articles-148.html to cut off oil exports. Funders forum louisiana http://www.g0all.com/111131/articles-490.html Sail cruise Of course, Hawaii falls state park http://www.g0all.com/111172/articles-620.html at one of my websites Hyperspace maryland http://www.g0all.com/111131/articles-266.html The Bush administration has finally How many hate incidents in indiana 2006 http://www.g0all.com/111172/articles-528.html the whole bookstore was inphp Taylor michigan obituaries http://www.g0all.com/111131/articles-290.html is made to sell other Louisiana vital records registry http://www.g0all.com/111131/articles-603.html they needed to add another University of florida college of education http://www.g0all.com/111172/articles-606.html by Michael Jackson with 14 Maryland department of motor vehicles http://www.g0all.com/111131/articles-268.html by creating Senior Living Services Mcdonogh school maryland http://www.g0all.com/111131/articles-455.html the world's reserve currency. Death dave smith idaho http://www.g0all.com/111172/articles-155.html bring about intensification of certain Georgia cherokee ancestors http://www.g0all.com/111172/articles-535.html money supply, trade and budget Pickens county builder association georgia http://www.g0all.com/111172/articles-589.html debt in the system. If Video audio broadcast of purdue michigan game http://www.g0all.com/111131/articles-494.html entirely from Toyota’s success. http://www.usatoday.com/money/autos/2007-05-02-toyota-lean-usat_N.htm The edelweis frankenmuth michigan http://www.g0all.com/111131/articles-630.html more than sixty percent since Illinois state fill in income tax forms http://www.g0all.com/111172/articles-681.html receive the most quality, highest Carpet and ceramic tile store kansas city http://www.g0all.com/111131/articles-371.html because of it's dangerous nature. teen protection act indiana http://www.g0all.com/111172/articles-557.html out. This is bogus, illegal Central michigan computer repair http://www.g0all.com/111131/articles-78.html His clients have been featured Cna iowa registry http://www.g0all.com/111172/articles-244.html a national debt that our Bead clubs in michigan http://www.g0all.com/111131/articles-279.html lifestyle images is on the Bowie maryland newspaper http://www.g0all.com/111131/articles-637.html exercise, and try to drink North hampton public schools massachusetts http://www.g0all.com/111131/articles-629.html to look at one of City of brandon florida http://www.g0all.com/111172/articles-403.html swiss cheese that is being Romantic getaway portland maine http://www.g0all.com/111131/articles-276.html on what has been called Davis field dayton kentucky http://www.g0all.com/111131/articles-126.html use the employer's service. My Mcmillan elementry idaho http://www.g0all.com/111172/articles-267.html producer and co-founder of the Louisiana wood smoke products http://www.g0all.com/111131/articles-508.html Asked about the impending Maine live webcams http://www.g0all.com/111131/articles-533.html he was 18 or 19, Babson park elementary lake wales florida http://www.g0all.com/111172/articles-198.html you should strive to understand Michigan dental wellness http://www.g0all.com/111131/articles-574.html and used in a grand Food city maine http://www.g0all.com/111131/articles-159.html While Honda was leading the Usa track and field massachusetts http://www.g0all.com/111131/articles-147.html on-line presence making them hard Athletic training degree kentucky http://www.g0all.com/111131/articles-261.html outside of the United States, Event listings in louisville kentucky http://www.g0all.com/111131/articles-183.html that, those “illegally downloading” music Migraine trials in georgia http://www.g0all.com/111172/articles-505.html falling, will it continue to John deere dealer emporia kansas http://www.g0all.com/111131/articles-76.html heart." Most commendably, he Temerowski public information hawaii http://www.g0all.com/111172/articles-527.html

Add Comment

JVC Camcorder with Ubuntu - Also a bit on media in ubuntu

Posted on Sat Sep 20th, 2008 07:10pm

First of all - I just discovered the Medibuntu repository - which has a TON of extra support in the avcodec area... everyone who has ubuntu should follow THIS GUY's advice and add the repository using these two commands....

sudo wget http://www.medibuntu.org/sources.list.d/hardy.list -O /etc/apt/sources.list.d/medibuntu.list
wget -q http://packages.medibuntu.org/medibuntu-key.gpg -O - | sudo apt-key add - && sudo apt-get update

Now that being said - here's my situation. Right before getting extremely tired of Windows I bought a JVC GZ-MG130U at firesale price from BestBuy courtesy of a price match at Wal-Mart. Great little camcorder.

The camera is great, but it records to its internal harddisk in some 'MOD' format - Which is apparently a container codec for MPEG2 video and AC3 audio. Well, that doesn't exactly store well or play well much of anywhere. It DOES play after I download several codecs - and ONLY in mplayer, even VLC can't figure out what kind of video it is!

Well, I think MPEG4 would be great - and there is an open source implementation called XVID - so I'll just use transcode to fix it. Here's a script that I wrote that helps convert these things quickly. "convt.sh"

You need to apt-get install the "transcode" package for this to work.

#!/bin/bash
echo $1 | sed s/'MOD'/'AVI'/ | xargs transcode -i $1 -y xvid -Z 720x480 -o

As a  note - the transition from 4:3 to 16:9 sucks.

The script is (as usual) ghetto fabulous. It spits the filename (param1) into sed, which replaces MOD with AVI, and then pipes that as the output of an xarg'd transcode with the original filename (param1) as the input file. I've got it hooked up with a batch conversion script below.

#!/bin/bash
for i in *.MOD; do ./convt.sh $i; done;
v=`date +%y-%m-%d_%H:%M`
mkdir $v
mv *.AVI ./$v/
rm *.MOD

The script runs the original "convt.sh" on all the MOD files in the local directory, then moves all the resulting AVI files into a new folder - named after the time the script was ran. It then deletes all the other files.

The really efficient way to do this would be to add the RM to the original script so you don't end up doubling the number of videos on disk at one point. Instead of 2N storage space, you'd be left with N+1 for a brief instant, then back to N. Anyhow...

Time to go eat. More later on video converting and making a script to convert these to FLV when I upload them.

Show Comments (0)

Add Comment

Ghettofabulous modifications for TinyMCE - uploading images the REAL easy way

Posted on Fri Sep 19th, 2008 04:56am

I googled for 30 minutes today and was SHOCKED to find that no one had copy-paste code available that modified TinyMCE to accept uploaded images. Well, I found lots of code that did exactly what I was after, but it was all bloat. I've noticed a tendency for programmers to avoid doing things the easy way in favor of doing things the 'cool' way. Now there's an eternal struggle here between time involved, code maintainability, and robustness.

As all programmers, I have somewhat of an ego - even though I would say I am no expert. This code is the REAL easy way to modify TinyMCE to accept image uploads. There are some steps I will list beyond what is required, you may ignore them. The general idea is that once a picture is uploaded, you COULD just tell a user to copy and paste the image URL from one area to another in the same window - explained later - but my method automatically moves the src over. This code uses a PHP backend, but the METHOD works in any language. Its rudimentary.

This is several steps, but all of them are very basic.

  1. Download and unzip TinyMCE. I started by taking the 'advanced' example and modifying it.
  2. Take the tiny_mce folder and copy it to your web server. As is.
  3. Copy the TinyMCE.init method from the example file, and modify it to your liking. I simply rearranged buttons, and removed some bloat. Sample code below...
    <script type="text/javascript" src="<?= $base_url ?>/js/tiny_mce/tiny_mce.js"></script>
    <script type="text/javascript">
    tinyMCE.init({
    // General options
    mode : "textareas",
    theme : "advanced",
    plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

    // Theme options
    theme_advanced_buttons1 : "styleselect,fontsizeselect,formatselect,bold,italic,underline,strikethrough,|,bullist,numlist,|,outdent,indent,blockquote,|,justifyleft,justifycenter,justifyright,justifyfull,|,link,unlink,anchor,image,|,forecolor,backcolor,|,iespell,media,advhr,|,nonbreaking,pagebreak",
    theme_advanced_buttons2 : "template,styleprops,|,visualaid,visualchars,|,hr,|,cut,copy,paste,pastetext,pasteword,|,undo,redo,|,search,replace,|,tablecontrols,|,code,cleanup,removeformat",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,

    // Example content CSS (should be your site CSS)
    content_css : "<?= $base_url ?>/css/default.css",

    });
    </script>
    <textarea name="text" id="text" rows="20"></textarea>
  4. Save it. Check it out. Look good? Awesome.
  5. Open up /tiny_mce/plugins/advimage/image.html in your favorite editor. This is the page that tinymce calls as a template for the image editing button. This is where we'd like to upload our images, because users know the button with the picture means put a picture on the page.
  6. Around line 50 on the normal image.htm you'll see some table-rows (FOR SHAME TINY MCE!) that are used to line things up. There isn't any text that you'll recognize because TinyMCE pulls its language from another file, just incase someone who doesn't speak english wants to use the plugin. We are going to add another row with an IFRAME in it. Why an IFRAME? Because its an easy way to embed a separate form in the middle of an existing one without BORKING what already works. My modified code is below...
    							<tr>
    <td><label for="src_list">{#advimage_dlg.image_list}</label></td>
    <td><select id="src_list" name="src_list" onchange="document.getElementById('src'). [ TRIMMED FOR LENGTH ]
    </tr>
    SNIP HERE! -----------------------------------------------
    <tr>
    <td class="column1"><label id="titlelabel" for="title">{#advimage_dlg.fsrc}</label></td>
    <td colspan="2"><iframe src="upload.htm" style="height: 24px; width: 300px;" scrolling="no" frameborder="0"></iframe></td>
    </tr>
    ABOVE IS WHAT I ADDED ------------------------------
    <tr>
    <td class="column1"><label id="altlabel" for="alt">{#advimage_dlg.alt}</label></td>
    <td colspan="2"><input id="alt" name="alt" type="text" value="" /></td>
    </tr>
  7. That's all to adding the box.... Now we need to add the actual file uploading FORM in upload.html - which is the SRC listed for the iframe.
  8. Open a new file in your favorite editor and save it in the SAME tinymce/plugins/advimage/ folder as "upload.htm". All you're doing is making a quick and dirty form to handle the upload. NOTE: This is where I went slightly above and beyond and it wasn't required! Instead of having a submit button, I simply wanted the control to GO as soon as the image was selected. I added some funky javascript using a Timeout Function because OnChange has issues for security reasons. Here is the code I used... There is a lot wrong with it programmatically. (style and javascript in the head)
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>

    <style>
    body { margin: 0px; padding:0px; }
    input { border: solid black 1px; }
    </style>

    <!-- Unnecessary if you just add a submit button -->
    <script type="text/javascript">
    function go() {

    if(document.getElementById('upload').value != ''){
    alert('ho');
    document.getElementById('uploadform').submit();
    } else {
    setTimeout('go()',1000);
    }
    }
    window.onload = go;
    </script>
    <!-- Unnecessary if you just add a submit button -->

    </head>
    <body>
    <form action="uploader.php" method="post" id="uploadform" enctype="multipart/form-data">
    <input type="file" name="upload" id="upload" />
    <!-- add a submit button here if you want to make it easy -->
    </form>
    </body>
    </html>
  9. Save. You should now be able to clear your cache and refresh your page using the tinyMCE editor and see the box. Now we add the handler. Your handler can do whatever you like... mine is only moderately fancy. A *SIMPLE* upload form would do one of two things, spit out an error message when there is a problem, or return the URL that a user can copy/paste into the SRC field right above it. AGAIN I WENT A STEP BEYOND THE BASICS - I set mine up so that when the image is uploaded, it generates a URL for the picture, then reloads the PARENT frame (the actual image form) and sets the SRC by passing it as a parameter. Here's my code BUILT FOR MY FRAMEWORK... I have whittled it down so you get the idea and can make it work on your own. Note how in the previous code I set my form action to "uploader.php" - that's the file we'll be making.
    <?

    if (!is_uploaded_file($_FILES['upload']['tmp_name'])) {
    echo "problem!";
    } else {
       //do your business here with "move_uploaded_file"...

    //This is where you could just spit out a URL for your image, my code sends out a page that causes the parent frame to reload as described above
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>

    <style>
    body { margin: 0px; padding:0px; }
    input { border: solid black 1px; }
    </style>

    <script type="text/javascript">
    function go() {
    //this "change_parent_url" bit will be addressed in a sec, all that matters is that you set your image URL in the src= parameter
    // note how this is image.php instead of image.htm ? My server only runs php code on .php files. Step 11 explains how to
    // modify TinyMCE so changing the filename won't screw things up. Its really easy.
    parent.change_parent_url('image.php?src=YOUR_IMAGE_URL');
    }
    window.onload = setTimeout('go()',1000);
    </script>

    </head>
    <body>
    Adding image...
    </body>
    </html>
    <?
    }
    ?>
  10. Ok - to review, we've got the image tool modified, the form created, and the backend up. Now I just need to finish going above and beyond by modifying the image.htm to now be my new image.php script - so the "change_parent_url" function is defined, and so my src is prepopulated. Again, this part is highly unnecessary doing this the simple way of making a user copy/paste the URL for the image. Insert the first snippet in the top of [what is now still] image.htm , and then modify your script to match the second snippet - which prefills the SRC.
    	<script type="text/javascript">
    function change_parent_url(url)
    {
    document.location=url;
    }
    </script>


    ----- This code is normally around line 35 - note that all I did is put a simple PHP injection into the value="" attribute.

    <tr>
    <td class="column1"><label id="srclabel" for="src">{#advimage_dlg.src}</label></td>
    <td colspan="2"><table border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td><input name="src" type="text" id="src" value="<?= $_GET['src'] ?>" class="mceFocus" onchange="ImageDialog.showPreviewImage(this.value);" /></td>
    <td id="srcbrowsercontainer">&nbsp;</td>
    </tr>
    </table></td>
    </tr>
  11. OK! Now we're all done modifying that file, and want to save it as image.php so the php code will process. BUT WAIT - Zomg TINYMCE WILL STILL BE LOOKING FOR IMAGE.HTM! WHAT EVER SHALL I DO? This was the easiest part. Modify 
      /tinymce/plugins/advimage/editor_plugin.js ---- do a search replace on "image.htm" and put in "image.php". It should hit once. Save. YOU ARE DONE! HOORAY!

Again, this is not the PERFECT way to do this - but I wanted something that was quick and dirty and I managed this in about 30 minutes of hacking around. Enjoy!

 

Also - I leave you with this quick thought - color safe bleach is a JOKE! The idea that bleach doesn't change colors should tell you something about what you're trying to do. "Well I want THIS color to come out, but not THAT one!" This capability only exists with borg nanoprobes - and voodoo magic.

"When your tools become part of the problem, you aren't heading in the right direction."

Show Comments (0)

Add Comment

Inefficient Image Resizing with PHP

Posted on Thu Sep 18th, 2008 04:27am

This code is absolute CRAP, that is your warning! I had a bug in my logic today involving a resizing algorithm that automatically crops images. The example (working) is below...

The problem lies in that sometimes you don't know how an image will be resized, but you want to maintain some semblance of an aspect ratio so the image isn't "squished". This means that when width and height are both specified and the aspect ratio (width / height) is different, the image will be either "short and fat" or "tall and skinny". [aspect ratio is either bigger or smaller than the original]. If the image is short and fat, then you'll want to trim some off of the bottom --- if the opposite, you'll want to trim some off of the side.

Well, its trivial - but for some reason my brain wasn't engaged today - so I figured I'd offer up my code so people can steal it.

Pie ChartThis is the original image - notice how the pie is round.

Pie ChartThis image I specified a smaller height - and you can see that instead of squishing the image, it was cropped.

Pie ChartThis image was taller and skinnier, so the resizing happened as well as some cropping on the x axis.

Anyway ---- All of this so I could steal a funny picture from Digg. Crap code follows - it should be optimized by calling ImageSX and ImageSY once only.... Enjoy low hanging fruit. :) This code works on top of my company's proprietary web development framework as a standalone script. I added comments to help you. I was originally doing this using the absolute aspect ratio... its logically easier to understand when you use two "resize ratio" variables.

<?

require_once('../inc/config.php'); //delete this if you aren't using Element

$pic = new Picture($_GET['id']); //do your own SQL here

if($pic->getID()){ //your own method for making sure the picture is valid
$src_img=ImageCreateFromJPEG($pic->getField('localfile')); //replace the ImageCreate param with your own image file
} else {
$src_img=ImageCreateFromJPEG($base_path.'upload/jpg/noimage.jpg'); //your default image
}

$src_aspect = ImageSX($src_img) / ImageSY($src_img);

$_GET['width'] = intval($_GET['width']);
$_GET['height'] = intval($_GET['height']);

if(!isset($_GET['width'])){
$_GET['width'] = 800;
}

if(!isset($_GET['height'])){
$_GET['height'] = (float)ImageSY($src_img) * ((float)$_GET['width']/(float)ImageSX($src_img));
}

if(isset($_GET['width']) && isset($_GET['height'])){

$dst_aspect = $_GET['width'] / $_GET['height'];
$rsz_y = $_GET['height'] / ImageSY($src_img);
$rsz_x = $_GET['width'] / ImageSX($src_img);

if($dst_aspect >= $src_aspect){
//image is wider than original
//get whole width
$crop_width = ImageSX($src_img);
//trim from bottom
$crop_height = $_GET['height'] * (1/$rsz_x);
} else {
//image is taller than original
//get whole height
$crop_height = ImageSY($src_img);
//trim from right
$crop_width = $_GET['width'] * (1/$rsz_y);
}
//at this point you know your destination bounds, source bounds, and they've been cropped if necessary
}

$dst_img=ImageCreateTrueColor($_GET['width'],$_GET['height']);

ImageCopyResampled($dst_img,$src_img,0,0,0,0,$_GET['width'],$_GET['height'],$crop_width,$crop_height);

ob_start('ob_gzhandler'); //compress the image because if its huge, load time sucks.

Header("Content-type: image/jpeg");
ImageJPEG($dst_img,'',100);

ob_end_flush();


//free the memory used for the images
ImageDestroy($src_img);
ImageDestroy($dst_img);
?>
Show Comments (0)

Add Comment

Linux Audio Commands

Posted on Wed Sep 17th, 2008 02:24am

This blog was started mainly because I keep finding all these linux commands and want to note them somewhere... if you found this and these help you out - or you find me entertaining - I welcome your feedback!

 

On Ubuntu 8.04 with the mplayer and lame packages, you can decompress just about anything (WMA, MP3, MP4, OGG, FLAC, etc) - and throw it into a nice tidy MP3 file at convenience.

To uncomopress an audio file into a wav....

 mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader [INPUT FILENAME] 

My understanding is that the -vo and -vc options specify the video-out and video-codec options since mplayer is actually designed for video, which are irrelevant to audio. -af is an "audio format" flag - resample=44100 resamples the audio to a standard bitrate (44100 = cd quality) - ao = "audio out" , pcm:waveheader means to format to a Pulse Controlled Modulation with a wavefile header.

Then again, I may be wrong on all of this. :) That's just how I understand it. I will say that it sucks getting a standard BS 'audiodump.wav' file output. There's probably an option to name the output that I missed.

The command to compress to MP3 is...

lame -m j -h --vbr-new -b 160 [INPUT FILE] -o [OUTPUT FILE]

LAME = LAME Ain't an MP3 Encoder, but it really is. OPTIONS: -m = mode, j means joint stereo, (Inspect this with [man lame] - some people don't like the quality), -h is a quality increasing options that isn't very well explained - its necessary for VBR (variable bit rate) encoding though.... -b is the bitrate setting, when used with --vbr-new, the new VBR algorithm it will set the average bitrate to 160 when compressing the file (slightly above CD quality). -o simply means output to file named.

Over and out.

Show Comments (0)

Add Comment

Testing 123

Posted on Wed Sep 17th, 2008 02:13am

This is a big fat freaking test.

Show Comments (0)

Add Comment


[ Login | Logout ]