Skip to content

Instantly share code, notes, and snippets.

@daliborgogic
Created July 3, 2014 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daliborgogic/e314d17a08123cc1c2dc to your computer and use it in GitHub Desktop.
Save daliborgogic/e314d17a08123cc1c2dc to your computer and use it in GitHub Desktop.
latest
<?php
ob_start();
session_start();
include '../../php/connection.php';
ini_set("gd.jpeg_ignore_warning", 1);
//========================================= FUNCTIONALITIES ============================
$name=addslashes($_POST['name']);
$surname=addslashes($_POST['surname']);
$email=addslashes($_POST['email']);
$mobile=addslashes($_POST['mobile']);
$picture_url=addslashes($_POST['picture_url']);
$id_korisnika=addslashes($_POST['id_korisnika']);
$radio_btn=addslashes($_POST['radio_btn']);
$kampanja=addslashes($_POST['kampanja']);
$picture_url = explode('temp/',$picture_url);
$picture_url = $picture_url[1];
$picture_url_1 = explode('.',$picture_url);
$picture_url_1 = $picture_url_1[0];
$images_sticker = $_POST['images_sticker'];
$images_sticker = json_decode($images_sticker);
$images_frame = $_POST['images_frame'];
$images_frame = json_decode($images_frame);
$text_element = $_POST['text_element'];
$text_element = json_decode($text_element);
if($name!=''){
if($surname!=''){
if($email!=''){
if($mobile!=''){
if(preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^", $email) && $ticket_provera==false){
$slika_new = $picture_url_1.".png";
if( file_exists('../../temp/'.$slika_new) ){
copy("../../temp/".$picture_url_1.".png","../../pictures/user/pictures/".$picture_url_1.".png");
$image_to_display = imagecreatetruecolor(410, 410);
$white = imagecolorallocate($image_to_display, 255, 255, 255);
imagefill($image_to_display, 0, 0, $white);
$images_fronte = '../../pictures/user/pictures/'.$picture_url_1.'.png';
$source_image = imagecreatefrompng($images_fronte);
}else{
copy("../../temp/".$picture_url,"../../pictures/user/pictures/".$picture_url);
$image_to_display = imagecreatetruecolor(410, 410);
$white = imagecolorallocate($image_to_display, 255, 255, 255);
imagefill($image_to_display, 0, 0, $white);
$images_fronte = '../../pictures/user/pictures/'.$picture_url;
$source_image = imagecreatefromjpeg($images_fronte);
}
imagecopy ( $image_to_display , $source_image , 0 , 0 , 0 , 0 , 410 , 410 );
for($i=0;$i<sizeof($images_sticker);$i++){
$image_src = $images_sticker[$i][0];
$image_src = str_replace('http://belgradecreative.com/_facebook/fitness/','../../',$image_src);
$image_width = $images_sticker[$i][1];
$image_height = $images_sticker[$i][2];
$image_top = $images_sticker[$i][3];
$image_top = $image_top;
$image_left = $images_sticker[$i][4];
$image_left = $image_left;
$slika_ext = explode('.',$image_src);
$slika_ext = $slika_ext[sizeof($slika_ext)-1];
switch(strtolower($slika_ext)){
case 'jpg': {$slika_nalepiti = imagecreatefromjpeg($image_src);}; break;
case 'jpeg': {$slika_nalepiti = imagecreatefromjpeg($image_src);}; break;
case 'gif': {$slika_nalepiti = imagecreatefromgif($image_src);}; break;
case 'png': {$slika_nalepiti = imagecreatefrompng($image_src);}; break;
}
list($image_old_width,$image_old_height) = getimagesize($image_src);
imagecopyresampled($image_to_display,$slika_nalepiti,$image_left,$image_top,0,0,$image_width,$image_height,'100','100');
}
for($i=0;$i<sizeof($text_element);$i++){
//=================EXPLODE BOJE==========================
$boja = explode(',',$text_element[$i][4]);
$boja_1 = explode('rgb(',$boja[0]);
$boja_1 = $boja_1[1];
$boja_2 = $boja[1];
$boja_3 = explode(')',$boja[2]);
$boja_3 = $boja_3[0];
$velicina = explode('px',$text_element[$i][0]);
$velicina = $velicina[0];
$velicina *= 0.78;
$black = imagecolorallocate($image_to_display,$boja_1,$boja_2,$boja_3);
//=============================OLJACA problem ============================
//=============================OLJACA problem ============================
$propotion = (($velicina/0.7)*19)/48;
$text_element[$i][11] = str_replace('px','',$text_element[$i][8]);
$number_of_letters = $text_element[$i][8]/$propotion;
$tekst = $text_element[$i][7];
$promenjiva_tekst = '';
$counter = 0;
//=============================OLJACA problem ============================
if($text_element[$i][3]=='normal'){
$font = '../../fonts/d6e767ca-8efd-405f-b1e0-964985cb73f9.ttf';
}
if($text_element[$i][3] == 'italic' && $text_element[$i][2]!= 'bold'){
$font = '../../fonts/7007c8f4-45dd-40a3-9790-ac60dc8b7372.ttf';
}
if($text_element[$i][3] == 'italic' && $text_element[$i][2] == 'bold'){
$font = '../../fonts/03e387d6-a134-4896-ae92-73fee022912d.ttf';
}
if($text_element[$i][3] == 'normal' && $text_element[$i][2] == 'bold'){
$font = '../../fonts/0ebe822a-9f3a-44dc-a4e2-8d039563f8ac.ttf';
}
//==============================oljaka====================================
$words = explode(" ", $tekst);
$string = "";
$tmp_string = "";
$font_size = $velicina;
$color = $black;
$image = $image_to_display;
$max_width = 371;
$font_size = $velicina;
$start_x = $text_element[$i][6];
$start_y = $text_element[$i][5]+45;
for($j = 0; $j < count($words); $j++) {
$tmp_string .= $words[$j]." ";
//check size of string
$dim = imagettfbbox($font_size, 0, $font, $tmp_string);
if($dim[4] < ($max_width - $start_x)) {
$string = $tmp_string;
$curr_width = $dim[4];
} else {
$j--;
$tmp_string = "";
var_dump($text_element[$i][1]);
if($text_element[$i][1] == 'left'){
//left
$start_xx = $start_x + round(($max_width - $curr_width - $start_x) / 2);
imagettftext($image, $font_size, 0, $start_x+19, $start_y, $color, $font, $string);
}
if($text_element[$i][1] == 'right'){
//right
$start_xx = round(($max_width - $curr_width - $start_x) );
imagettftext($image, $font_size, 0, $start_xx+25, $start_y, $color, $font, $string);
}
if($text_element[$i][1] == 'center'){
//center
$start_xx = $start_x + round(($max_width - $curr_width - $start_x) / 2);
imagettftext($image, $font_size, 0, $start_xx+19, $start_y, $color, $font, $string);
}
$string = "";
// line height lol
$start_y += (abs($dim[5]) * 1.2);
$curr_width = 0;
}
}
if($text_element[$i][1] == 'left'){
// left
$start_xx = $start_x - round(($max_width - $dim[4] - $start_x) / 2);
imagettftext($image, $font_size, 0, $start_x+19, $start_y, $color, $font, $string);
}
if($text_element[$i][1] == 'right'){
$start_xx = round(($max_width - $curr_width - $start_x) );
imagettftext($image, $font_size, 0, $start_xx+19, $start_y, $color, $font, $string);
}
//center
if($text_element[$i][1] == 'center'){
$start_xx = $start_x + round(($max_width - $curr_width - $start_x) / 2);
imagettftext($image, $font_size, 0, $start_xx+19, $start_y, $color, $font, $string);
}
//}
}
//$fronte_slika = 'fronte_'.time().'.jpg';
imagepng($image_to_display,'../../pictures/user/pictures/'.$picture_url, 0);
//============================
//===========================DODAVANJE ELEMENATA NA SLIKU STICKER=======================================
$image_to_display = imagecreatetruecolor(410, 410);
$white = imagecolorallocate($image_to_display, 255, 255, 255);
imagefill($image_to_display, 0, 0, $white);
$images_fronte = '../../pictures/user/pictures/'.$picture_url;
$source_image = imagecreatefromjpeg($images_fronte);
imagecopy ( $image_to_display , $source_image , 0 , 0 , 0 , 0 , 410 , 410 );
for($i=0;$i<sizeof($images_frame);$i++){
$image_src = $images_frame[$i][0];
$image_src = str_replace('http://belgradecreative.com/_facebook/fitness/','../../',$image_src);
$image_width = $images_frame[$i][1];
$image_height = $images_frame[$i][2];
$image_top = $images_frame[$i][3];
$image_left = $images_frame[$i][4];
$slika_ext = explode('.',$image_src);
$slika_ext = $slika_ext[sizeof($slika_ext)-1];
switch(strtolower($slika_ext)){
case 'jpg': {$slika_nalepiti = imagecreatefromjpeg($image_src);}; break;
case 'jpeg': {$slika_nalepiti = imagecreatefromjpeg($image_src);}; break;
case 'gif': {$slika_nalepiti = imagecreatefromgif($image_src);}; break;
case 'png': {$slika_nalepiti = imagecreatefrompng($image_src);}; break;
}
list($image_old_width,$image_old_height) = getimagesize($image_src);
imagecopyresampled($image_to_display,$slika_nalepiti,$image_left,$image_top,0,0,$image_width,$image_height,'410','410');
}
imagepng($image_to_display,'../../pictures/user/pictures/'.$picture_url, 0);
//============================
$sql="INSERT INTO user VALUES(NULL,'".$name."','".$surname."','".$email."','".$mobile."','".$picture_url."',".$id_korisnika.",'".$radio_btn."',".$kampanja.",0,0,0)";
mysql_query($sql);
$id_uce = mysql_insert_id();
echo '|success|You have successfully entered the picture|'.$picture_url.'|'.$id_uce;
}else{
echo '|error|Please enter a valid email address';
}
}else{
echo '|error|Please enter your mobile number!';
}
}else{
echo '|error|Please enter your email!';
}
}else{
echo '|error|Please enter your surname!';
}
}else{
echo '|error|Please enter your name!';
}
ob_flush();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment