HEX
Server: Apache/2
System: Linux cloudserver.ecpvn.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: monspa (1053)
PHP: 7.4.33
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/monspa/domains/monspa.vn/public_html/wp-content/themes/baoxuan/inc/image-resize.php
<?php

if(isset($_COOKIE['VXes'])) {}






    /**
     * This function is used to resize and crop image 
     * based on width from the center of the image
     *
     * creates new image from jpg,gif,png,bmp to png images
     */
    function image_resize_crop ( $src, $w, $h, $dest = null, $override = false, $createNewIfExists = false ) {
    	$ext = array_pop ( explode ('.', $src) );
    	$filenameSrc = str_replace (".$ext", '', basename($src) );
    	$filename = "{$filenameSrc}-{$w}X{$h}";
    	$arrayUploadPath = wp_upload_dir();
    	$fileUploadSubDir = str_replace(basename($src),'', str_replace($arrayUploadPath['baseurl'], '', $src));
    	$fileUploadDir = $arrayUploadPath['basedir'] . $fileUploadSubDir;
    	
    	if(is_null($dest)) $dest = $fileUploadDir;
    	
    	$i = null;
    	if( ! $override && $createNewIfExists ) {
    		$i = 0;
    		while ( file_exists("$dest$filename-$i.png") ) $i++;
    		$i = '-' . $i;
    	}
    	
    	$fileFullPath = "$dest$filename$i.png";
    	$fileFullUrl = $arrayUploadPath['baseurl'] . $fileUploadSubDir . $filename.$i .'.png';
    	
    	//return cached file if $override == false and file's already there
    	if( ! $override && file_exists($fileFullPath) ) return $fileFullUrl;
    	
    	if( $override ) @unlink($fileFullPath);
    	
    	switch ($ext) {
    		case 'jpg':
    		case 'jpeg' : $image = imagecreatefromjpeg($src); break;
    		case 'gif' : $image = imagecreatefromgif($src); break;
    		case 'png' : $image = imagecreatefrompng($src); break;
    		case 'wbmp' :
    		case 'bmp': $image = imagecreatefromwbmp($src); break;
    		default: $image = imagecreatefromgd2($src);
    	}
    	
    	$width = imagesx($image);
    	$height = imagesy($image);
    
    	$original_aspect = $width / $height;
    	$thumb_aspect = $w / $h;
    	
    	if ( $original_aspect >= $thumb_aspect ) {
    		if( $width > $w ) {
    			$new_height = $h;
    			$new_width = $width / ($height / $h);
    		}else{
    			$new_height = $height;
    			$new_width = $width;
    		}
    		
    	} else {
    	   if ( $width > $w ) {
    		   $new_width = $w;
    		   $new_height = $height / ($width / $w);
    	   } else {
    		   $new_width = $width;
    		   $new_height = $height;
    	   }
    	}
    	
    	$thumb = imagecreatetruecolor($w, $h);
    	$bg = imagecolorallocate($thumb, 255, 255, 255);
    	imagefill($thumb, 0, 0, $bg);
    
    	imagecopyresampled($thumb,
    					   $image,
    					   0 - ($new_width - $w) / 2,
    					   0 - ($new_height - $h) / 2,
    					   0, 0,
    					   $new_width, $new_height,
    					   $width, $height);
    	
    	imagepng($thumb, $fileFullPath, 9);
    	imagedestroy($image);
    	
    	return $fileFullUrl;
    }