function transparent_avatar_with_position($video_width, $video_height, $uid, $dir = 'data', $default_transparent = 'trans.gif', $videos_frames) { $converted_avatars = array(); $converted_path = $dir . "/{$uid}/converted"; if (!file_exists("{$converted_path}")) { exec("mkdir -p {$converted_path}"); } exec("chmod 777 -R {$converted_path}/.."); exec("rm -rf {$converted_path}/*"); #include get_template_directory() . '/video_libs/data.php'; /*include get_template_directory() . '/video_libs/data_live.php'; $videos_frames = get_data_videos($_REQUEST['uid'], $_REQUEST['eid']);*/ $i = 1; $text_transparent_filename = $dir . "/{$uid}/trans_{$video_width}_{$video_height}.gif"; exec("convert {$default_transparent} -background none -extent {$video_width}x{$video_height} {$text_transparent_filename}"); $default_transparent_2 = $default_transparent; foreach ($videos_frames as $key => $item) { $default_transparent = $default_transparent_2; $filename = $item->imageFrame; $image_objs = isset($item->imageFace) ? $item->imageFace : array(); $text_objs = isset($item->text) ? $item->text : array(); $curr_avatar = NULL; if (!empty($image_objs)) { foreach ($image_objs as $image_obj) { $new_avatar_path = resize_avatar($image_obj->width, $image_obj->height, $uid, $image_obj->src, $image_obj->opacity, $dir); $name = generate_filename($i); $curr_avatar = "{$converted_path}/{$name}"; $positions = explode(',', $image_obj->position); $command = "convert {$default_transparent} -background none -extent {$video_width}x{$video_height} -draw \"image SrcOver {$positions[0]},{$positions[1]} {$image_obj->width},{$image_obj->height} '{$new_avatar_path}'\" {$curr_avatar}"; $msg = exec($command); $default_transparent = $curr_avatar; } } /*if (!empty($text_objs)) { foreach ($text_objs as $text_obj) { $picin = new Imagick(isset($curr_avatar) ? $curr_avatar : $text_transparent_filename); $draw = new ImagickDraw(); $draw->setTextEncoding('utf-8'); $draw->setFillColor("rgba(255, 255, 255, {$text_obj->opacity})"); $draw->setFont($text_obj->font); $draw->setFontSize($text_obj->size); $positions = explode(',', $text_obj->position); $picin->annotateImage($draw, $positions[0], $positions[1], 0, $text_obj->text); if (!isset($curr_avatar)) { $name = generate_filename($i); $curr_avatar = "{$converted_path}/{$name}"; } $picin->writeimage($curr_avatar); } }*/ $converted_avatars[$filename] = $curr_avatar; unset($curr_avatar); $i++; } return $converted_avatars; }
/** * Resize the avatar by the given data. * * @param Request $request * @return mixed * * @author Cali */ public static function resize(Request $request) { $old_avatar = $request->user()->localAvatar(); $path = storage_path('app/' . $old_avatar->src); $resized_avatar = resize_avatar($path, intval($request->width), intval($request->height), intval($request->x), intval($request->y)); $avatar = new Avatar(['type' => Avatar::TYPE_LOCAL, 'src' => $old_avatar->src]); $request->user()->avatars()->save($avatar); return $resized_avatar; }