Created
October 10, 2012 12:19
-
-
Save reformatco/3865249 to your computer and use it in GitHub Desktop.
Fix Scissors Cropping in Wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// scissors.php in Scissors Continued | |
// Source: http://wordpress.org/support/topic/plugin-scissors-continued-custom-image-sizes-arent-handled | |
function scissors_admin_head() | |
{ | |
if(strstr($_SERVER['REQUEST_URI'], 'media')) | |
{ | |
global $scissors_dirname, $_wp_additional_image_sizes; | |
wp_enqueue_script('scissors_crop', '/' . PLUGINDIR . '/'.$scissors_dirname.'/js/jquery.Jcrop.js', array('jquery') ); | |
wp_enqueue_script('scissors_js', '/' . PLUGINDIR . '/'.$scissors_dirname.'/js/scissors.js' ); | |
$thisUrl = admin_url('admin-ajax.php'); | |
echo "<!-- JS loaded for Scissors in media library -->\n"; | |
echo "<script type='text/javascript'>\n/* <![CDATA[ */\n"; | |
echo "scissors = {\n"; | |
echo "ajaxUrl: '$thisUrl'"; | |
$intermediate_image_sizes = get_intermediate_image_sizes(); | |
foreach ($intermediate_image_sizes as $size) { | |
if ($size=='large' || $size=='medium' || $size=='thumbnail') { | |
// standard WP sizes large, medium, thumbmnail | |
$width = intval(get_option("{$size}_size_w")); | |
$height = intval(get_option("{$size}_size_h")); | |
$aspectRatio = max(1, $width) / max(1, $height); | |
if(!get_option("{$size}_crop")) $aspectRatio = 0; | |
} else { | |
if (isset($_wp_additional_image_sizes[$size])) { | |
$width = $_wp_additional_image_sizes[$size]['width']; | |
$height = $_wp_additional_image_sizes[$size]['height']; | |
$aspectRatio = max(1, $width) / max(1, $height); | |
if(!$_wp_additional_image_sizes[$size]['crop']) $aspectRatio = 0; | |
} else { | |
$aspectRatio = 0; | |
} | |
} | |
echo ",\n'{$size}AspectRatio': $aspectRatio"; | |
} | |
echo "\n}\n"; | |
echo "/* ]]> */\n</script>\n"; | |
echo "<!-- End of JS loaded for Scissors in media library -->\n"; | |
} | |
} | |
function scissors_crop($post, $srcfile, $src) | |
{ | |
global $_wp_additional_image_sizes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment