Skip to content

Instantly share code, notes, and snippets.

View matt-thomas's full-sized avatar

Matt Thomas matt-thomas

View GitHub Profile
@benob
benob / exif_rotate.py
Created May 27, 2019 07:32
Rotate pictures according to EXIF orientation tag, in python using PIL. Supports all 8 orientations with a simple transposition operation.
# Proper exif rotation with PIL. Handles all the cases in https://github.com/recurser/exif-orientation-examples
from PIL import Image
image = Image.open(filename)
exif = image._getexif()
ORIENTATION = 274
if exif is not None and ORIENTATION in exif:
orientation = exif[ORIENTATION]
method = {2: Image.FLIP_LEFT_RIGHT, 4: Image.FLIP_TOP_BOTTOM, 8: Image.ROTATE_90, 3: Image.ROTATE_180, 6: Image.ROTATE_270, 5: Image.TRANSPOSE, 7: Image.TRANSVERSE}
if orientation in method:
@aramboyajyan
aramboyajyan / snippet.php
Created February 7, 2016 09:54
Drupal 7 Commerce empty user shopping cart programmatically
global $user;
$order = commerce_cart_order_load($user->uid);
commerce_cart_order_empty($order);
@sherakama
sherakama / CCK Machine Name Change
Created November 7, 2013 18:33
How to rename a cck field machine's name in Drupal 7.x
$fields = array(
'field_my_fields' => 'field_my_new_field',
'field_other_field' => 'field_adam_west',
);
// Loop through each of the fields/tables with the old name and change them
foreach($fields as $field_name => $new_field_name) {
// First check that field_name exists
if(!db_table_exists('field_data_' . $field_name)) {
@jaywilliams
jaywilliams / convert_ascii.php
Created May 28, 2009 19:25
This simple function will remove any non-ASCII character. Feel free to fork and extend!
<?php
/**
* Remove any non-ASCII characters and convert known non-ASCII characters
* to their ASCII equivalents, if possible.
*
* @param string $string
* @return string $string
* @author Jay Williams <myd3.com>
* @license MIT License
* @link http://gist.github.com/119517