Support » Plugin: Avatar Privacy » PHP Fatal error: avprimg://image_editor/dummy/path.jpg

  • Resolved alx359

    (@alx359)


    The plugin is breaking WP backend when installed together with other well-known image-sharping plugins. Tested with sharpen-resized-images and imagemagick-sharpen-resized-images.

    While trying to change my Profile Picture (superadmin), as per the AP feature, the following kind of error occurred:

    PHP Fatal error: Uncaught ImagickException: unable to open image 'avprimg://image_editor/dummy/path.jpg': No such file or directory @ error/blob.c/OpenBlob/2712 in /public/wp-content/plugins/sharpen-resized-images/ajx-sharpen-resized-images.php:65

    Their offending line says:
    $image->writeImage( $resized_file );

    The error is theirs, but the const DEFAULT_STREAM = 'avprimg://image_editor/dummy/path'; is yours, located in \avatar-privacy\includes\avatar-privacy\tools\images\class-editor.php:39.

    This is the first time I got issues with those sharpen plugins. Please advise how to make AP play ball with those.

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author pepe

    (@pputzer)

    It looks like those plugins are not compatible with PHP stream wrappers. The avprimg prefix is registered for Avatar Privacy’s custom in-memory stream wrapper (eliminating filesystem access during avatar resizing).

    The sharpen-resized-images plugin is quite short actually. Have added a try-catch to the impeding line to avoid the crash. What would you suggest to make it compatible?

    add_filter('image_make_intermediate_size', 'ajx_sharpen_resized_files',900);
    function ajx_sharpen_resized_files( $resized_file ) {
    	
    	$progressive_jpg = apply_filters('sharpen_resized_progressive_jpg', true);
    
    	$size = @getimagesize( $resized_file );
    	if ( !$size )
    		return new WP_Error('invalid_image', __('Could not read image size'), $file);
    	list($orig_w, $orig_h, $orig_type) = $size;
    
    	switch ( $orig_type ) {
    		case IMAGETYPE_JPEG:
    			switch ( _wp_image_editor_choose() ) {
    
    				case "WP_Image_Editor_Imagick":
    				
    					$image = new Imagick( $resized_file );
    					
    					$image->unsharpMaskImage(0, 0.5 , 1, 0.05);
    
    					$image->setImageCompression(Imagick::COMPRESSION_JPEG); 
    					$image->setImageCompressionQuality(apply_filters( 'jpeg_quality', 90, 'edit_image' )); 
    
    					//$image->stripImage(); 
    					
    					if($progressive_jpg) $image->setInterlaceScheme(Imagick::INTERLACE_PLANE); // Progressive JPEG on
    					
    					//alx359:try-catch
                        try {
                            $image->writeImage( $resized_file ); // Create Image
                        }
    					catch (Exception $e) { // can't sharp, so return unsharped
                            return $resized_file;
                        }
                        
    					$image->clear();
    					$image->destroy();					
    					
    					break;
    				
    				case "WP_Image_Editor_GD":
    				default:
    					$image = imagecreatefromstring( file_get_contents( $resized_file ) );
    
    					$matrix = array(
    						array(apply_filters('sharpen_resized_corner',-1.2), apply_filters('sharpen_resized_side',-1), apply_filters('sharpen_resized_corner',-1.2)),
    						array(apply_filters('sharpen_resized_side',-1), apply_filters('sharpen_resized_center',20), apply_filters('sharpen_resized_side',-1)),
    						array(apply_filters('sharpen_resized_corner',-1.2), apply_filters('sharpen_resized_side',-1), apply_filters('sharpen_resized_corner',-1.2)),
    					);
    
    					$divisor = array_sum(array_map('array_sum', $matrix));
    					$offset = 0;
    					// Sharpen Image
    					imageconvolution($image, $matrix, $divisor, $offset);
    					// Progressive JPEG on
    					if($progressive_jpg) imageinterlace($image, true); 
    					// Create Image
    					imagejpeg($image, $resized_file,apply_filters( 'jpeg_quality', 90, 'edit_image' ));
    
    					// we don't need images in memory anymore
    					imagedestroy( $image );
    					
    			}
    			break;
    		case IMAGETYPE_PNG:
    			break;
    		case IMAGETYPE_GIF:
    			break;
    	}	
    
    	return $resized_file;
    }	
    
    Plugin Author pepe

    (@pputzer)

    Well, it would need to provide some hooks – as is this is pretty nasty code from a compatibility standpoint, because there is no way of opting out of the sharpening (and the use of _wp_image_editor_choose is not compatible with a lot of other plugins that provide their own subclasses of WP_Image_Editor).

    Since this has not been updated in 4 years, I’d suggest looking for another plugin. For a quick fix, you need to use Imagick::writeImageFile instead of ::writeImage. See #42663 for details.

    That was an useful hint. Thanks!

    Instead of this:
    $image->writeImage( $resized_file );

    This:
    $image->writeImageFile( $resized_file );

    and now it isn’t crashing anymore for me with imagick.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.