function getResources($uploads_dir, $id, $maxWidth, $connection = 'default') { $attachments = Attachment::on($connection)->where('id', $id)->get(); if (count($attachments) == 1) { $attachment = $attachments[0]; switch ($attachment->source) { case Source::EMAIL: $adapter = new Local($uploads_dir . '/email/'); break; case Source::TWITTER: $adapter = new Local($uploads_dir . '/twitter/'); break; case Source::TELEGRAM: $adapter = new Local($uploads_dir . '/telegram/'); break; default: break; } $filesystem = new Filesystem($adapter); $filesystem->addPlugin(new ListWith()); if ($filesystem->has($attachment->filePath)) { $data = $filesystem->read($attachment->filePath); $fp['data'] = $data; $fp['mime'] = $filesystem->getMimetype($attachment->filePath); if ($maxWidth > 0) { $imagine = new \Imagine\Gd\Imagine(); $image = $imagine->load($data); $size = $image->getSize(); if ($size->getWidth() > $maxWidth) { // AWIDTH : AHEIGHT = NWIDTH : NHEIGHT // HHEIGHT = AHEIGHT * NWIDTH / AWIDTH $height = $size->getHeight() * $maxWidth / $size->getWidth(); $width = $maxWidth; $fp['data'] = $image->resize(new Box($width, $height), ImageInterface::FILTER_UNDEFINED)->show('png'); //FILTER_QUADRATIC } } return $fp; } } return false; }
$evaluation->setConnection($connection_name); $evaluation->save(); } $imageCount = 0; if (isset($elem_search->entities->media)) { foreach ($elem_search->entities->media as $media) { $imageCount++; $resources[] = $media->media_url; $dataImg = file_get_contents($media->media_url); $filename = basename($media->media_url); //"http://pbs.twimg.com/media/CPbPvS6UkAE7dYw.jpg", if ('' == trim($filename)) { $url = $media->expanded_url; $parts = parse_url($url); // /Nonsprecare/status/645894353769111552/photo/1 echo $parts['path']; $str = explode('/', $parts['path']); $filename = $str[4]; } $filesystem->put($id_tweet . '/' . $filename, $dataImg); $attachments = new Attachment(array('annotation_id' => $annotation->id, 'source' => Source::TWITTER, 'fileName' => $filename, 'filePath' => $id_tweet . '/' . $filename)); $attachments->setConnection($connection_name); $attachments->save(); } } } } $filesystem->put('last.tweet', $lastId); } catch (\Exception $e) { $log->addError($e->getFile() . ' on ' . $e->getLine() . ' ' . ' because : ' . $e->getMessage()); }