Kako dodati ovako nesto pri uploadu slike?

Da li se ovako nesto moze uraditi pomocu PHP-a ili…?

Ovako dodajem slike.

function create_thumb($src,$dest,$desired_width){
    $f=array();
    $fparts = pathinfo($src);
    $ext = strtolower($fparts['extension']);
    if (!in_array($ext,array('gif','jpg','png','jpeg'))) return false;
    if ($ext == 'gif')$resource = imagecreatefromgif($src);
    else if ($ext == 'png')$resource = imagecreatefrompng($src);
    else if ($ext == 'jpg' || $ext == 'jpeg')$resource = imagecreatefromjpeg($src);

    $width = imagesx($resource);
    $height = imagesy($resource);
    $f[widthBefore]=$width;
    $f[heightBefore]=$height;
    $desired_height = 600;
    $desired_width = floor($width * ($desired_height / $height));
    $virtual_image = imagecreatetruecolor($desired_width,$desired_height);
    imagecopyresampled($virtual_image,$resource,0,0,0,0,$desired_width,$desired_height,$width,$height);
    if ($ext == 'gif') imagegif($virtual_image,$dest);
    else if ($ext == 'png') imagepng($virtual_image,$dest);
    else if ($ext == 'jpg' || $ext == 'jpeg') imagejpeg($virtual_image,$dest);
    return $f;
}

 function create_s_thumb($src,$dest,$desired_thumb_width){
    $f=array();
    $fparts = pathinfo($src);
    $ext = strtolower($fparts['extension']);
    if (!in_array($ext,array('gif','jpg','png','jpeg'))) return false;
    if ($ext == 'gif')$resource = imagecreatefromgif($src);
    else if ($ext == 'png')$resource = imagecreatefrompng($src);
    else if ($ext == 'jpg' || $ext == 'jpeg')$resource = imagecreatefromjpeg($src);
	$width = imagesx($resource);
    $height = imagesy($resource);
    $f[widthBefore]=$width;
    $f[heightBefore]=$height;
	$desired_thumb_height = 90;
    $desired_thumb_width = floor($width * ($desired_thumb_height / $height));
    $virtual_image = imagecreatetruecolor($desired_thumb_width,$desired_thumb_height);
    imagecopyresampled($virtual_image,$resource,0,0,0,0,$desired_thumb_width,$desired_thumb_height,$width,$height);
    if ($ext == 'gif') imagegif($virtual_image,$dest);
    else if ($ext == 'png') imagepng($virtual_image,$dest);
    else if ($ext == 'jpg' || $ext == 'jpeg') imagejpeg($virtual_image,$dest);
    return $f;
}

if ($_FILES){
    $desired_width;
    for ($i=0;$i<count($_FILES['file']['name']);$i++){
        $ran_num =  mt_rand().mt_rand().mt_rand();
        $allowedExts = array("gif", "jpeg", "jpg", "png", "JPG");
        $allowedTypes=array("image/gif","image/jpeg","image/jpg","image/pjpeg","image/x-png","image/png","image/JPG");
        $temp = explode(".", $_FILES["file"]["name"][$i]);
        $extension = end($temp);
        if (in_array($_FILES['file']['type'][$i],$allowedTypes) && in_array($extension,$allowedExts) && $_FILES["file"]["size"][$i] < 5000000 && $_FILES["file"]["error"][$i]==0) {
            if (file_exists("upload/".$i ."_".$ran_num . $_FILES["file"]["name"][$i])){
            } else {
                if (move_uploaded_file($_FILES["file"]["tmp_name"][$i],"upload/".$i ."_" .$ran_num. $_FILES["file"]["name"][$i])){
                	if (create_thumb("upload/" .$i ."_" .$ran_num. $_FILES["file"]["name"][$i],"upload/" .$i ."_" .$ran_num. $_FILES["file"]["name"][$i],$desired_width)){}
                    if ($i==0){
                    (create_s_thumb("upload/" .$i ."_" .$ran_num. $_FILES["file"]["name"][$i],"thumbs/" .$i ."_" .$ran_num. $_FILES["file"]["name"][$i],$desired_thumb_width));
						$thumb="/images/". "thumbs/" .$i ."_" .$ran_num. $_FILES["file"]["name"][$i];
						$query = mysqli_query($con,"INSERT INTO `uploaded_thumbs` ( `id` , `thumb`,`id_oglasa` ) VALUES ( NULL ,'".$thumb."','".$id."' )");
					}
                       else {
                           
                       }
    			    $slika= "/images/". "upload/" .$i ."_" .$ran_num. $_FILES["file"]["name"][$i];
                    $q = mysqli_query($con,"INSERT INTO `uploaded_images` ( `id` , `slika`, `id_oglasa` ) VALUES ( NULL , '".$slika."','".$id."' )");
                }
            }
        }
    }
 
}

Preko photoshopa, stavis daj logo i sačuvaš sliku

Zato ti treba http://php.net/manual/en/book.imagick.php i mozes ovaj tutorijal uzeti http://php.net/manual/en/image.examples-watermark.php ili ovaj http://www.codeforest.net/add-watermark-on-image-using-php

Ne treba ti nikakav Photoshop za to.

@creatifcode Hvala cini mi se da je to to. Gledam ovo preko telefona i nije mi bas najjasnije.Jel to trebam da napisem kao funkciju pa da je posle pozovem u petlji ili…?

<?php

$target_file = "image.jpg";
$wtrmrk_file = "watermark.png";
$new_file = "new_image.jpg";
make_watermark($target_file, $wtrmrk_file, $new_file);

function make_watermark($target, $wtrmrk_file, $newcopy) { 
    $watermark = imagecreatefrompng($wtrmrk_file); 
    imagealphablending($watermark, false); 
    imagesavealpha($watermark, true); 
    $img = imagecreatefromjpeg($target);
    $img_w = imagesx($img); 
    $img_h = imagesy($img); 
    $wtrmrk_w = imagesx($watermark); 
    $wtrmrk_h = imagesy($watermark); 
    $dst_x = ($img_w / 2) - ($wtrmrk_w / 2);
    $dst_y = ($img_h / 2) - ($wtrmrk_h / 2); 
    imagecopy($img, $watermark, $dst_x, $dst_y, 0, 0, $wtrmrk_w, $wtrmrk_h); 
    imagejpeg($img, $newcopy, 100); 
    imagedestroy($img); 
    imagedestroy($watermark); 
}


?>

Hvala @shimi! Isprobacu kad se vratim s’ posla. Predpostavljam da bih ovu funkciju trebalo pozvati odmah posle one za resize slike.

Ovo ti postavlja watermark na sredinu slike…

@shimi
Neznam negde uporno gresim.
Stalno mi izbacuje :
PHP Fatal error: Call to undefined function make_watermark()
Ne kapiram gde trebam konkretno da pozovem funkciju u mom kodu i koji parametar da joj prosledim!?

@shimi
Neznam negde uporno gresim.
Stalno mi izbacuje :
PHP Fatal error: Call to undefined function make_watermark()
Ne kapiram gde trebam konkretno da pozovem funkciju u mom kodu i koji parametar da joj prosledim!?

Pa, po ovome ispada ili da nemaš funkciju make_watermark ili da se ne load-a file u kojem je funkcija make_watermark. Shimi poziva funkciju ovdje: make_watermark($target_file, $wtrmrk_file, $new_file); , a ispod je funkcija.


Copyright © 2020 WM Forum - AboutContact - Sponsored by: Mydataknox & Profit Monkey