{"action":"created","issue":{"url":"https://api.github.com/repos/plank/laravel-mediable/issues/10","repository_url":"https://api.github.com/repos/plank/laravel-mediable","labels_url":"https://api.github.com/repos/plank/laravel-mediable/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/plank/laravel-mediable/issues/10/comments","events_url":"https://api.github.com/repos/plank/laravel-mediable/issues/10/events","html_url":"https://github.com/plank/laravel-mediable/issues/10","id":171045160,"number":10,"title":"Intervention Image","user":{"login":"grafikkaos","id":124558,"avatar_url":"https://avatars.githubusercontent.com/u/124558?v=3","gravatar_id":"","url":"https://api.github.com/users/grafikkaos","html_url":"https://github.com/grafikkaos","followers_url":"https://api.github.com/users/grafikkaos/followers","following_url":"https://api.github.com/users/grafikkaos/following{/other_user}","gists_url":"https://api.github.com/users/grafikkaos/gists{/gist_id}","starred_url":"https://api.github.com/users/grafikkaos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grafikkaos/subscriptions","organizations_url":"https://api.github.com/users/grafikkaos/orgs","repos_url":"https://api.github.com/users/grafikkaos/repos","events_url":"https://api.github.com/users/grafikkaos/events{/privacy}","received_events_url":"https://api.github.com/users/grafikkaos/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-14T06:39:29Z","updated_at":"2016-08-14T20:01:02Z","closed_at":null,"body":"Hi,\r\n\r\nCame across your package and I have to say it has been a time save when it comes to uploading media files for different models. Many thanks for that.\r\n\r\nI have a small question, I am trying to generate thumbnail for images that are uploaded and the intervention image class is my go to class when resizing images.  While I can write the code to generate the thumbnails to individual folders / disks, is there a way I can tap into this using your package?\r\n\r\nFor example when uploading files, the **fromSource** method is used.  Is there a method that I can use to upload a generated thumbnail e.g **MediaUploaded::fromFile($thumbnail)->upload()**. $thumbnail coming from something like **$thumbnail = Image::make('foo.jpg')->resize(300, 200);**\r\n\r\nAny thoughts would be great!\r\n\r\nThanks\r\n\r\nEmmanuel"},"comment":{"url":"https://api.github.com/repos/plank/laravel-mediable/issues/comments/239693541","html_url":"https://github.com/plank/laravel-mediable/issues/10#issuecomment-239693541","issue_url":"https://api.github.com/repos/plank/laravel-mediable/issues/10","id":239693541,"user":{"login":"frasmage","id":916652,"avatar_url":"https://avatars.githubusercontent.com/u/916652?v=3","gravatar_id":"","url":"https://api.github.com/users/frasmage","html_url":"https://github.com/frasmage","followers_url":"https://api.github.com/users/frasmage/followers","following_url":"https://api.github.com/users/frasmage/following{/other_user}","gists_url":"https://api.github.com/users/frasmage/gists{/gist_id}","starred_url":"https://api.github.com/users/frasmage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frasmage/subscriptions","organizations_url":"https://api.github.com/users/frasmage/orgs","repos_url":"https://api.github.com/users/frasmage/repos","events_url":"https://api.github.com/users/frasmage/events{/privacy}","received_events_url":"https://api.github.com/users/frasmage/received_events","type":"User","site_admin":false},"created_at":"2016-08-14T20:01:02Z","updated_at":"2016-08-14T20:01:02Z","body":"Hi @grafikkaos,\r\n\r\nFirst of all, thanks for your interest in this project! I'm glad you are enjoying it.\r\n\r\nAs for your question, the `MediaUploader::fromFile()` method can accept a number of different inputs, including absolute file paths. You could do something like this:\r\n\r\n```php\r\n$tmp = tempnam(sys_get_temp_dir(),'image'); // store in a temporary location\r\nrename($tmp, $tmp = $tmp . '.jpg'); //uploader needs an extension to read\r\n$image = Image::make($media->getAbsolutePath())\r\n\t->resize(300, 200)\r\n\t->save($tmp);\r\n\r\nMediaUploader::fromSource($tmp)\r\n\t->toDestination($disk, 'thumbnails')\r\n\t->upload();\r\n```\r\n\r\nIf you are dealing with particularly large files and moving from tmp to disk is a speed issue, you could have intervention place the file directly on the disk and then populate the `Media` record yourself.\r\n\r\n```php\r\n$path = public_path('uploads/thumbnails');\r\n$image = Image::make($media->getAbsolutePath())\r\n\t->resize(300, 200)\r\n\t->save($path);\r\n\r\n$thumb = new Media;\r\n$thumb->disk = 'uploads';\r\n$thumb->directory = 'thumbnails';\r\n$thumb->filename = $media->getKey();\r\n$thumb->extension = 'jpg';\r\n$thumb->mime_type = 'image/jpeg';\r\n$thumb->aggregate_type = Media::TYPE_IMAGE;\r\n$thumb->size = filesize($path);\r\n$thumb->save();\r\n```\r\n\r\nIf you need to maintain the association of the `Media` to its thumbnail, the implementation is entirely up to you – there is no single right answer here. You could save all thumbnails under the key of the original model (as in my example above), subclass `Media` and give a hasOne relationship to itself, etc.\r\n\r\nA completely different approach that I have used for resizing media is [League/Glide](https://github.com/thephpleague/glide), which resizes images on the fly based on HTTP query parameters and handles its own caching. The advantage here is that you don't need to duplicate your Media records and it can spit out any number of sizes on the fly.\r\n\r\nYou are not the first to mention having a means to import images being output by resizing package.  I don't have any intention of adding built-in support for any one package or tool, since I would rather keep this package open-ended and let each users' use case dictate implementation, but I might add some functions to make something like approach 2 above easier to implement. "}}
{"actor":{"display_login":"frasmage"}}