public function cropPhotoAction(Request $request) { $jpeg_quality = 90; $filename = $request->get('filename'); $day_num = $request->get('day_num'); $x = $request->get('x-coord'); $y = $request->get('y-coord'); $targ_w = $request->get('width'); $targ_h = $request->get('height'); $width = 515; $height = 770; $uploadRootDir = $this->container->get('kernel')->getRootdir() . '/../web/uploads/travel_guide_temp'; $src = $uploadRootDir . '/' . $filename; $pathInfo = pathinfo($src); if ($pathInfo['extension'] == 'png') { $img_r = imagecreatefrompng($src); } else { $img_r = imagecreatefromjpeg($src); } $dst_r = ImageCreateTrueColor($width, $height); // crop imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $width, $height, $targ_w, $targ_h); $targetDir = $this->container->get('kernel')->getRootdir() . '/../web/uploads/travel_guide_photos'; if (!is_writable($targetDir)) { mkdir("{$targetDir}", 0755); } $target = $targetDir . '/' . $filename; imagejpeg($dst_r, $target, $jpeg_quality); // upload image to amazon s3 // @author NRL <*****@*****.**> $sourceFile = $target; $key = $this->get('buggl_main.constants')->get('EGUIDE_PHOTOS') . $filename; $this->get('buggl_aws.wrapper')->upload($sourceFile, $key); // $webPath = 'http://'.$request->getHost().'/uploads/travel_guide_photos/' . $filename; $baseUrl = $this->get('buggl_main.constants')->get('S3_BASE_URL'); $webPath = $baseUrl . $key; $eguide = $this->getDoctrine()->getRepository('BugglMainBundle:EGuide')->findOneById($request->get('eguide_id')); $eguidePhotos = $this->getDoctrine()->getRepository('BugglMainBundle:EGuidePhoto')->findBy(array('e_guide' => $eguide, 'type' => $request->get('photo-type'), 'status' => 1)); foreach ($eguidePhotos as $iObj) { $iObj->setStatus(2); $em = $this->getDoctrine()->getEntityManager(); $em->persist($iObj); $em->flush(); } $eguidePhoto = new EGuidePhoto(); $eguidePhoto->setEGuide($eguide); $eguidePhoto->setPhoto($webPath); $eguidePhoto->setType($request->get('photo-type')); $eguidePhoto->setStatus(1); $em = $this->getDoctrine()->getEntityManager(); $em->persist($eguidePhoto); $em->flush(); $response = array('url' => $webPath, 'filename' => $filename); if ($day_num > 0) { $itinerary = $this->getDoctrine()->getRepository('BugglMainBundle:Itinerary')->findOneBy(array('e_guide' => $eguide, 'day_num' => $day_num)); if (!$itinerary) { $itinerary = new Itinerary(); $itinerary->setEGuide($eguide); $itinerary->setDayNum($day_num); } $itinerary->setEGuidePhoto($eguidePhoto); $em->persist($itinerary); $em->flush(); $response = array_merge($response, array('itinerary_id' => $itinerary->getId())); } return new JsonResponse($response, 200, array("Content-Type" => "text/plain")); }