Skip to content

Instantly share code, notes, and snippets.

@reformatco
Created October 10, 2012 12:19
Show Gist options
  • Select an option

  • Save reformatco/3865249 to your computer and use it in GitHub Desktop.

Select an option

Save reformatco/3865249 to your computer and use it in GitHub Desktop.

Revisions

  1. @benpalmer79 benpalmer79 revised this gist Oct 10, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    // scissors.php in Scissors Continued
    // Source: http://wordpress.org/support/topic/plugin-scissors-continued-custom-image-sizes-arent-handled

    function scissors_admin_head()
    {
  2. @benpalmer79 benpalmer79 created this gist Oct 10, 2012.
    48 changes: 48 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    // scissors.php in Scissors Continued

    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;