WordPress.org

Ready to get started?Download WordPress

Forums

Scissors Continued
Custom image sizes aren't handled (9 posts)

  1. Helen Hou-Sandi
    WordPress Dev
    Posted 3 years ago #

    When you do a crop (whether full chain or specific), custom image sizes added via add_image_size are replaced but with the full size of the crop, rather than the specified image size. Proportions are also from the crop itself, not as defined.

    http://wordpress.org/extend/plugins/scissors-continued/

  2. Kitefr
    Member
    Posted 2 years ago #

    i wanted to push this one topic because it's the only thing who still annoying me with this plugin...

    Otherwise, it is really great !

    I hope an update of the plugin will be come very soon...

  3. pixeline
    Member
    Posted 2 years ago #

    Indeed, a fix would be nice. In the meanwhile, everytime you scissor an image, make sure to rebuild thumbnails using the "rebuild thumbnails" plugin.

  4. Apollo139
    Member
    Posted 2 years ago #

    Hi there is a solution:

    1) open the file scissors.php in folder wp-content/plugins/scissors-continued
    2) find function scissors_admin_head(), it is somewhere arround 887 line
    3) uncomment (or delete) line with this command:

    foreach(array('large', 'medium', 'thumbnail') as $size)"

    4) add two new lines:

    $intermediate_image_sizes = get_intermediate_image_sizes();
    foreach ($intermediate_image_sizes as $size)

    5) that's all

    notes:
    – be sure about cache, sometimes it needed to referesh page more than one time
    – the name of custom sizes shouldn't have any space; "MyCustomSize" is correctly instead of "My Custom Size"

    I've tested it only in one site, so that I don't guarantee functionality.

    If you have any idea or feedbacks, please, write it.

    Alex

  5. Apollo139
    Member
    Posted 2 years ago #

    Just one note:
    – I use plugin "Simple Image Size" for add custom image size
    – I've checked that I have to change a few times a "crop" settings until the Crop function will works
    – You can check correct functionality the Crop function if you show source code of admin page (Media->AnyImage->Edit, Settings->Media) and inside of <head></head> tag find:

    <script type='text/javascript'>
    /* <![CDATA[ */
    scissors = {
    ajaxUrl: 'http://mysite.com/wp-admin/admin-ajax.php',
    thumbnailAspectRatio: 2,
    mediumAspectRatio: 1,
    largeAspectRatio: 1.14285714286,
    MyCustomSize: 0.75,
    }
    /* ]]> */
    </script>

    Inside of this you should find the name of your custom image size (in my case "MyCustomSize") and correct aspect ratio (0.75). If there is "0" (zero) so here is some mistake. Try to delete it and add again, refresh page, change crop settings to false/true.

  6. Apollo139
    Member
    Posted 2 years ago #

    Hi,
    here is an update, which should works correctly: I send whole function scissors_admin_head()

    function scissors_admin_head()
    {
    	if(strstr($_SERVER['REQUEST_URI'], 'media'))
    	{
    		global $scissors_dirname;
    
    		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 {
    				// custom image sizes
    				$custom_image_sizes = get_option( 'custom_image_sizes' );
    				if (!empty($custom_image_sizes)) {
    					$width = $custom_image_sizes[$size]['w'];
    					$height = $custom_image_sizes[$size]['h'];
    					$aspectRatio = max(1, $width) / max(1, $height);
    					if(!$custom_image_sizes[$size]['c']) $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";
    	}
    }
  7. tomdizzle
    Member
    Posted 2 years ago #

    ales,
    doesnt work :(

  8. davidstinemetze
    Member
    Posted 2 years ago #

    Ales's solution appears to require the "Simple Image Size" plugin. Additionally, there seems to be a bug when "post-thumbnail" is a size option. Because post-thumbnail contains a hyphen, it's causing a JavaScript issue when it tries to declare the variable because it's not in quotes.

    I have modified Ales's hack so that it doesn't require you to install an additional plugin and fixed this post-thumbnail bug.

    First of all, I added the $_wp_additional_image_sizes variable to the global variable scope of the function.

    global $scissors_dirname, $_wp_additional_image_sizes;

    Now, when not dealing with standard sizes, it pulls the dimensions from the $_wp_additional_image_sizes variable.

    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;
    }

    Finally, to fix the post-thumbnail JavaScript issue, I changed

    echo ",\n{$size}AspectRatio: $aspectRatio";

    to

    echo ",\n'{$size}AspectRatio': $aspectRatio";

    So the final function should look something like this:

    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";
    	}
    }
  9. madisn
    Member
    Posted 2 years ago #

    Custom image sizes remain unchanged.
    Same fix should be used in the scissors_crop() function.

    function scissors_crop($post, $srcfile, $src)
    {
    	global $_wp_additional_image_sizes;
    .
    .
    .

    And line ~1250:

    if ($size=='large' || $size=='medium' || $size=='thumbnail') {
    $resized = scissors_image_make_intermediate_size($dstfile, get_option("{$size}_size_w"), get_option("{$size}_size_h"), get_option("{$size}_crop"), get_option("{$size}_adaptive"));
    }
    else{
    $nwidth = $_wp_additional_image_sizes[$size]['width'];
    $nheight = $_wp_additional_image_sizes[$size]['height'];
    $ncrop = $_wp_additional_image_sizes[$size]['crop'];
    $nadaptive = $_wp_additional_image_sizes[$size]['adaptive'];
    $resized = scissors_image_make_intermediate_size($dstfile, $nwidth, $nheight, $ncrop, $nadaptive);
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic