private static function computePictureCenter(&$media) { $filepath = $media->getMedia_filepath(); $center = ControleurMedia::computeCenter(ControleurMedia::getPictureFilepath($filepath, PictureSizeKind::BIG)); // Set big center $media->setCenter_big($center); $size = getimagesize(ControleurMedia::getPictureFilepath($filepath, PictureSizeKind::BIG)); $width_large = $size[0]; $height_large = $size[1]; $tmp = explode(';', $center); $x_center_big = $tmp[0]; $y_center_big = $tmp[1]; // Compute medium $size = getimagesize(ControleurMedia::getPictureFilepath($filepath, PictureSizeKind::MEDIUM)); $width_medium = $size[0]; $height_medium = $size[1]; $x_center_medium = ceil($x_center_big * $width_medium / $width_large); $y_center_medium = ceil($y_center_big * $height_medium / $height_large); $media->setCenter_medium($x_center_medium . ";" . $y_center_medium); // Compute small $size = getimagesize(ControleurMedia::getPictureFilepath($filepath, PictureSizeKind::SMALL)); $width_small = $size[0]; $height_small = $size[1]; $x_center_small = ceil($x_center_big * $width_small / $width_large); $y_center_small = ceil($y_center_big * $height_small / $height_large); $media->setCenter_small($x_center_small . ";" . $y_center_small); }
public function actionAddPlanPicture() { if (isset($_FILES) && count($_FILES) > 0 && ControleurRights::canAddPlans()) { $plan = new Plan(); $plan = Plan::getEntity($_POST['id_plan']); // Delete old picture if ($plan->getMedia_id() != null) { $old_media = Media::getEntity($plan->getMedia_id()); $old_media->deleteEntity(); } // Upload new picture $media_list = ControleurMedia::actionUploadNewMedia($_FILES, $_POST['id_plan'], $plan->getName()); // Save picture to plan $media = $media_list[0]; $media->setIs_main_media(true); $media->updateEntity(); $plan->setMedia_id($media->getId()); $plan->updateEntity(); } }
/** * @param string $filepath_small * Filepath_small * @return Media */ public function setFilepath_small() { $this->filepath_small = ControleurMedia::getAbsoluteAdress(ControleurMedia::getPictureFilepath($this->getMedia_filepath(), PictureSizeKind::SMALL)); return $this; }
/** * * Add media to objectId (which type is objectClass) * and use prefixColumn (column of objectClass) as filename prefix. * isMainMedia indicate if the upload picture is the main one of the object * * @param string $objectClass * @param string $objectId * @param string $prefixColumn * @param boolean $isMainMedia */ private static function addMedia($objectClass, $objectId, $prefixColumn, $isMainMedia) { if (isset($_FILES) && count($_FILES) > 0) { $entity = $objectClass::getEntity($objectId); // Delete old picture if ($entity->getMedia_id() != null) { $old_media = Media::getEntity($entity->getMedia_id()); $old_media->deleteEntity(); } // Upload new picture $func = 'get' . ucfirst($prefixColumn); $media_list = ControleurMedia::actionUploadNewMedia($_FILES, $objectId, $entity->{$func}()); // Save picture to project $media = $media_list[0]; $media->setIs_main_media($isMainMedia); $media->updateEntity(); $entity->setMedia_id($media->getId()); $entity->updateEntity(); return $entity; } }