private function getBrazzifiedImage($url, $logo_loc) { $valid_logo_locations = ['top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom', 'bottom-right']; try { $img = Image::make($url); } catch (\Exception $e) { return ['error' => 'Image or URL is not valid.']; } if (!in_array($logo_loc, $valid_logo_locations)) { return ['error' => 'Not a valid logo location.']; } $img->insert(base_path() . '/resources/images/brazzers-logo.png', $logo_loc, 10, 10); $finished_image = $img->encode('png'); $image_hash = hash('sha256', $finished_image . $logo_loc); $existing_image = ImageModel::where('hash', $image_hash)->first(); if ($existing_image) { $imgur_id = $existing_image->image_host_id; } else { $client = new Client(['base_uri' => 'https://api.imgur.com', 'timeout' => 10, 'headers' => ['Authorization' => 'Client-ID ' . env('IMGUR_CLIENT_ID')]]); $response = $client->request('POST', '3/image', ['form_params' => ['image' => base64_encode($finished_image), 'type' => 'base64', 'description' => 'Image generated by http://brazzify.me']]); if ($response->getStatusCode() != 200) { return ['error' => 'Error uploading image to imgur.']; } $imgur_response = json_decode($response->getBody()->getContents()); $imgur_id = $imgur_response->data->id; $image_model = new ImageModel(); $image_model->hash = $image_hash; $image_model->image_host = 1; $image_model->image_host_id = $imgur_id; $image_model->save(); } return ['imgur_id' => $imgur_id]; }
/** * Delete Image From Session folder, based on original filename */ public function delete($originalFilename) { $full_size_dir = Config::get('images.full_size'); $icon_size_dir = Config::get('images.icon_size'); $sessionImage = ImageModel::where('original_name', 'like', $originalFilename)->first(); if (empty($sessionImage)) { return Response::json(['error' => true, 'code' => 400], 400); } $full_path1 = $full_size_dir . $sessionImage->filename . '.jpg'; $full_path2 = $icon_size_dir . $sessionImage->filename . '.jpg'; if (File::exists($full_path1)) { File::delete($full_path1); } if (File::exists($full_path2)) { File::delete($full_path2); } if (!empty($sessionImage)) { $sessionImage->delete(); } return Response::json(['error' => false, 'code' => 200], 200); }