简体   繁体   中英

Adding Watermark to Ajax Crop

Im using Ajax Crop from enter link description here and I'd like to add a watermark to the script. The following is my script.

WATERMARK

$image_path = "watermark.png";

function watermark_image($oldimage_name, $new_image_name){
    global $image_path;
    list($owidth,$oheight) = getimagesize($oldimage_name);
    $width = 500; $height = 100;    
    $im = imagecreatetruecolor($width, $height);
    $img_src = imagecreatefromjpeg($oldimage_name);
    imagecopyresampled($im, $img_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
    $watermark = imagecreatefrompng($image_path);
    list($w_width, $w_height) = getimagesize($image_path);        
    $pos_x = $width - $w_width; 
    $pos_y = $height - $w_height;
    imagecopy($im, $watermark, $pos_x, $pos_y, 0, 0, $w_width, $w_height);
    imagejpeg($im, $new_image_name, 100);
    imagedestroy($im);
    unlink($oldimage_name);
    return true;
}

UPLOAD AND RESIZE PART

function resizeThumb($arr){

    $date = md5(time());    
    $arr['temp_uploadfile'] = $arr['img_src'];
$arr['new_uploadfile'] = $arr['uploaddir'].strtolower($date).'.jpg';

    asidoImg($arr);
    exit;
}

I tried adding

$arr = watermark_image($arr['temp_uploadfile'], $arr['uploaddir'].strtolower($date).'.jpg');

in place of

$arr['new_uploadfile'] = $arr['uploaddir'].strtolower($date).'.jpg';

but this didnt work.

Could someone help me?

Download the files and test

It turns out the script uses ASIDO and it has a built in WATERMARK TOOL. In func.php I done the following.

function asidoImg2($arr){

    include('asido/class.asido.php');
    asido::driver('gd');

    $height     = $arr['height'];
    $width      = $arr['width'];
    $x          = $arr['x'];
    $y          = $arr['y'];                

    // process
    $i1 = asido::image($arr['temp_uploadfile'], $arr['new_uploadfile']);    
    // fit and add white frame                                      
    if($arr['thumb'] === true){
        Asido::Crop($i1, $x, $y, $width, $height);
    asido::watermark($i1, 'watermark.png', ASIDO_WATERMARK_MIDDLE_LEFT, ASIDO_WATERMARK_SCALABLE_ENABLED, 1);

    }
    else{
        Asido::Frame($i1, $width, $height, Asido::Color(255, 255, 255));            
    asido::watermark($i1, 'watermark.png', ASIDO_WATERMARK_MIDDLE_LEFT, ASIDO_WATERMARK_SCALABLE_ENABLED, 1);
    }

    // always convert to jpg    
    Asido::convert($i1, 'image/jpg');

    $i1->Save(ASIDO_OVERWRITE_ENABLED);
        $data = array(
        'photo'=> $arr['new_uploadfile']
      );
        // echo $user_id;
    // delete old file
    echo $data['photo'];    

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM