Support » Plugin: : the only free Image Optimizer & compress plugin » Error in resizing (unserialize())

  • benw91



    I installed the plugin on my website and tried to run it to resize all the pictures that were already present. The progress was very slow and it doesn’t seem to have done anything. I tried to resize the single pictures as well and it didn’t work.
    I checked the debug log and I’m seeing this error:
    unserialize(): Error at offset 1635 of 2522 bytes in <path>/plugins/resmushit-image-optimizer/classes/resmushit.class.php on line 341
    I went into the file and the line throwing the error is:
    $tmp['attachment_metadata'] = isset($image->file_meta) ? unserialize($image->file_meta) : array();

    I have recently migrated my website and had to make manual changes in the database because of the changes in storage and URL. I’m not a PHP expert but as far as I understand the length of a value in serialized data is important when turning it into an array.
    Is my analysis correct? If so, I assume that the problem is in the postmeta table, but what kind of entries should I check?
    Sorry if this is confused, I don’t have any experience with PHP, I’m just trying to figure it out based on knowledge in other languages.



Viewing 1 replies (of 1 total)
  • Thread Starter benw91


    I added this code to generate the attachment_metadata array while making sure that the serialization is correct:

    		//Get function which checks whether serialization was correct
    		if(!function_exists("serialize_corrector")) {
    			function serialize_corrector($serialized_string){
    			// at first, check if "fixing" is really needed at all. After that, security checkup.
    				if ( @unserialize($serialized_string) !== true &&  preg_match('/^[aOs]:/', $serialized_string) ) {
    					$serialized_string = preg_replace_callback( '/s\:(\d+)\:\"(.*?)\";/s',    function($matches){return 's:'.strlen($matches[2]).':"'.$matches[2].'";'; },   $serialized_string );
    				return $serialized_string;
    		// Get the images in the attachement table
    		$all_images = $wpdb->get_results($queryUnoptimizedPicture);
    		foreach($all_images as $image){
    			$tmp = array();
    			$tmp['ID'] = $image->ID;
    			if (isset($image->file_meta)) {
    				$tmp_serialized_file_meta = serialize_corrector($image->file_meta);
    				$tmp['attachment_metadata'] = unserialize($tmp_serialized_file_meta);
    			else {
    				$tmp['attachment_metadata'] = array();

    Now I’m getting the following warning in the log when I try to optimize an image:
    PHP Warning: file_get_contents(<path&gt;.png): failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable
    in <path>/plugins/resmushit-image-optimizer/classes/resmushit.class.php on line 92
    On the UI no error is shown, it’s just shown as processing and nothing happens

Viewing 1 replies (of 1 total)
  • The topic ‘Error in resizing (unserialize())’ is closed to new replies.