Auto Orientate Image (Exif / PHP)

The following function will take an image path and automatically orientate it based on the images exif data. If it can’t find the exif data, it will do nothing!

function autoRotateImage($imagePath) {
	$exif = exif_read_data($imagePath);

	if(!isset($exif['Orientation'])) return;

	$ort = $exif['Orientation'];

	$image = imagecreatefromjpeg($imagePath);

	switch($ort) {
		case 3:
			$image = imagerotate($image, 180, 0);
			break;
		case 6:
			$image = imagerotate($image, -90, 0);
			break;
		case 8:
			$image = imagerotate($image, 90, 0);
			break;
	}

	imagejpeg($image, $imagePath);
}

Mimic Mac on Windows

All the below worked a treat for me…

Don’t make a habbit of using CTRL, swap it on Windows:

How to Remap Windows Keyboard Shortcuts in Boot Camp on a Mac

Then reverse the trackpad scroll too:

How to Get the Worst OS X Lion Feature in Windows (Reverse Scrolling)

Note: I added an extra line at the top of the reverse-scroll script to stop an annoying “max hotkeys per interval” dialog box popping up. Here’s my full AutoHotKey.ahk script:

#MaxHotkeysPerInterval 400

WheelUp::
Send {WheelDown}
Return

WheelDown::
Send {WheelUp}
Return

Split String Method C++ / CPP

Here is a method that allows you to split a string in C++ (CPP). I couldn’t find a decent one on the internet so I wrote my own. The method accepts a source string and splits it by the specified delimiter. It returns a vector. I hope someone finds this useful!

std::vector<string> splitString(std::string source, std::string delimiter)
{
    console() << "Splitting " << source << " :: at :: " << delimiter << std::endl;
    
    int len = source.length();
    std::vector<string> words;
    std::string prev = "";
    
    for(int i = 0; i < len; ++i)
    {
        std::string c = source.substr(i,1);
        
        if(c.compare(delimiter) != 0) prev = prev + c;
        
        if((c.compare(delimiter) == 0 || i == len-1) && prev.compare(delimiter) != -1) {
            words.push_back(prev);
            prev = "";
        }
    }
    
    return words;
}