Example #1
0
		function domain_get_screen_dimensions($domain) {
			$dom = $this->get_domain_object($domain);

			$tmp = libvirt_domain_get_screen_dimensions($dom, $this->get_hostname() );
			return ($tmp) ? $tmp : $this->_set_last_error();
		}
Example #2
0
/**
 * fetch and store a screenshot of an active virtual machine on the virt host
 *
 * @global  resource $host_conn      libvirt connection
 *
 * @param   string   $vm_virt_id     virt_id of the vm
 * @param   string   $virt_host_name virt_id of host
 * @param   int      $max_width      width of screenshot (height determined by ratio)
 *
 * @return  string              filename of JPG
 */
function ace_kvm_vm_screenshot($vm_virt_id, $virt_host_name, $max_width)
{
    global $host_conn;
    // $xSize = 160;
    // $ySize = 120;
    $vm_res = libvirt_domain_lookup_by_name($host_conn, $vm_virt_id);
    ace_kvm_log_last_error();
    $screenshot_dimensions = libvirt_domain_get_screen_dimensions($vm_res, $virt_host_name);
    ace_kvm_log_last_error();
    $screenshot_width = $screenshot_dimensions['width'];
    $screenshot_height = $screenshot_dimensions['height'];
    $resize_factor = $screenshot_width / $max_width;
    $desired_screenshot_width = ceil($screenshot_width / $resize_factor);
    $desired_screenshot_height = ceil($screenshot_height / $resize_factor);
    //$time[] = microtime(TRUE);
    $screenshot = libvirt_domain_get_screenshot_api($vm_res, 0);
    ace_kvm_log_last_error();
    if ($screenshot) {
        //$time[] = microtime(TRUE);
        $temp_filename = $screenshot['file'];
        //echo d($temp_filename);
        $image = new Imagick($temp_filename);
        $image->setFormat('jpeg');
        #resizeImage(xRes,yRes,FILTER,sharp/blurry,bestfit)
        //$image->resizeImage($desired_screenshot_width,$desired_screenshot_height,Imagick::FILTER_POINT,0.5,TRUE);
        //$time[] = microtime(TRUE);
        //echo d($image);
        $image->thumbnailimage(180, 0);
        //$time[] = microtime(TRUE);
        $jpg_filename = './screenshots/' . $vm_virt_id . '_thumb.jpg';
        $image->writeImage($jpg_filename);
        //$time[] = microtime(TRUE);
        $image->clear();
        $image->destroy();
        //$time[] = microtime(TRUE);
        unlink($temp_filename);
        #delete the /tmp/ file
        //$time[] = microtime(TRUE);
    } else {
        $jpg_filename = '';
    }
    /*
    echo '<pre>Screenshot timing';
    echo '<table>';
    echo '<tr><td>libvirt_domain_get_screenshot_api</td><td align="right">' . round((($time[1] - $time[0]) * 1000),3) . '</td></tr>';
    echo '<tr><td>$image = new Imagick($temp_filename)</td><td align="right">' . round((($time[2] - $time[1]) * 1000),3) . '</td></tr>';
    echo '<tr><td>$image->thumbnailimage(180,0)</td><td align="right">' . round((($time[3] - $time[2]) * 1000),3) . '</td></tr>';
    echo '<tr><td>$image->writeImage($jpg_filename)</td><td align="right">' . round((($time[4] - $time[3]) * 1000),3) . '</td></tr>';
    echo '<tr><td>$image->destroy()</td><td align="right">' . round((($time[5] - $time[4]) * 1000),3) . '</td></tr>';
    echo '<tr><td>unlink($temp_filename)</td><td align="right">' . round((($time[6] - $time[5]) * 1000),3) . '</td></tr>';
    echo '<tr><td>TOTAL</td><td align="right">' . round((($time[6] - $time[0]) * 1000),3) . '</td></tr>';
    echo '</table></pre>';
    echo d($time);
    */
    return $jpg_filename;
}