Cevaplar
-
Sanırım resim upload aşamasında bozuluyor, kırpma ve boyutlandırma kodlarını yazarsan daha kolay çözüm üretebiliriz..
-
alren
köşeleri kırpmak için
<?php
$image_file = $_GET [ 'src' ];
$corner_radius = isset( $_GET [ 'radius' ]) ? $_GET [ 'radius' ] : 20 ; // The default corner radius is set to 20px
$angle = isset( $_GET [ 'angle' ]) ? $_GET [ 'angle' ] : 0 ; // The default angle is set to 0º
$topleft = (isset( $_GET [ 'topleft' ]) and $_GET [ 'topleft' ] == "no" ) ? false : true ; // Top-left rounded corner is shown by default
$bottomleft = (isset( $_GET [ 'bottomleft' ]) and $_GET [ 'bottomleft' ] == "no" ) ? false : true ; // Bottom-left rounded corner is shown by default
$bottomright = (isset( $_GET [ 'bottomright' ]) and $_GET [ 'bottomright' ] == "no" ) ? false : true ; // Bottom-right rounded corner is shown by default
$topright = (isset( $_GET [ 'topright' ]) and $_GET [ 'topright' ] == "no" ) ? false : true ; // Top-right rounded corner is shown by default
$images_dir = 'images/' ;
$corner_source = imagecreatefrompng ( 'images/corner.png' );
$corner_width = imagesx ( $corner_source );
$corner_height = imagesy ( $corner_source );
$corner_resized = ImageCreateTrueColor ( $corner_radius , $corner_radius );
ImageCopyResampled ( $corner_resized , $corner_source , 0 , 0 , 0 , 0 , $corner_radius , $corner_radius , $corner_width , $corner_height );
$corner_width = imagesx ( $corner_resized );
$corner_height = imagesy ( $corner_resized );
$image = imagecreatetruecolor ( $corner_width , $corner_height );
$image = imagecreatefromjpeg ( $images_dir . $image_file ); // replace filename with $_GET['src']
$size = getimagesize ( $images_dir . $image_file ); // replace filename with $_GET['src']
$white = ImageColorAllocate ( $image , 255 , 255 , 255 );
$black = ImageColorAllocate ( $image , 0 , 0 , 0 );
// Top-left corner
if ( $topleft == true ) {
$dest_x = 0 ;
$dest_y = 0 ;
imagecolortransparent ( $corner_resized , $black );
imagecopymerge ( $image , $corner_resized , $dest_x , $dest_y , 0 , 0 , $corner_width , $corner_height , 100 );
}
// Bottom-left corner
if ( $bottomleft == true ) {
$dest_x = 0 ;
$dest_y = $size [ 1 ] - $corner_height ;
$rotated = imagerotate ( $corner_resized , 90 , 0 );
imagecolortransparent ( $rotated , $black );
imagecopymerge ( $image , $rotated , $dest_x , $dest_y , 0 , 0 , $corner_width , $corner_height , 100 );
}
// Bottom-right corner
if ( $bottomright == true ) {
$dest_x = $size [ 0 ] - $corner_width ;
$dest_y = $size [ 1 ] - $corner_height ;
$rotated = imagerotate ( $corner_resized , 180 , 0 );
imagecolortransparent ( $rotated , $black );
imagecopymerge ( $image , $rotated , $dest_x , $dest_y , 0 , 0 , $corner_width , $corner_height , 100 );
}
// Top-right corner
if ( $topright == true ) {
$dest_x = $size [ 0 ] - $corner_width ;
$dest_y = 0 ;
$rotated = imagerotate ( $corner_resized , 270 , 0 );
imagecolortransparent ( $rotated , $black );
imagecopymerge ( $image , $rotated , $dest_x , $dest_y , 0 , 0 , $corner_width , $corner_height , 100 );
}
// Rotate image
$image = imagerotate ( $image , $angle , $white );
// Output final image
imagejpeg ( $image );
imagedestroy ( $image );
imagedestroy ( $corner_source );
?>12 yıl önce yazılmış -
alren
boyutlandırmak için
<?php
class SimpleImage {
var $image;
var $image_type;
function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
$this->image = imagecreatefromjpeg($filename);
} elseif( $this->image_type == IMAGETYPE_GIF ) {
$this->image = imagecreatefromgif($filename);
} elseif( $this->image_type == IMAGETYPE_PNG ) {
$this->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image,$filename,$compression);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image,$filename);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image,$filename);
}
if( $permissions != null) {
chmod($filename,$permissions);
}
}
function output($image_type=IMAGETYPE_JPEG) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image);
}
}
function getWidth() {
return imagesx($this->image);
}
function getHeight() {
return imagesy($this->image);
}
function resizeToHeight($height) {
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width,$height);
}
function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width,$height);
}
function scale($scale) {
$width = $this->getWidth() * $scale/100;
$height = $this->getheight() * $scale/100;
$this->resize($width,$height);
}
function resize($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
}
?>12 yıl önce yazılmış
-