{"id":20513677,"url":"https://github.com/theopencms/crop_tool","last_synced_at":"2026-04-21T14:02:37.472Z","repository":{"id":71919597,"uuid":"84741326","full_name":"TheOpenCMS/crop_tool","owner":"TheOpenCMS","description":"Crop Tool for Rails","archived":false,"fork":false,"pushed_at":"2017-04-02T10:55:21.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-16T09:40:05.769Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheOpenCMS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-12T16:48:43.000Z","updated_at":"2017-03-12T16:49:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"18b90f53-1fbb-4059-aa67-4e5af9ec7952","html_url":"https://github.com/TheOpenCMS/crop_tool","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheOpenCMS%2Fcrop_tool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheOpenCMS%2Fcrop_tool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheOpenCMS%2Fcrop_tool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheOpenCMS%2Fcrop_tool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheOpenCMS","download_url":"https://codeload.github.com/TheOpenCMS/crop_tool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242117717,"owners_count":20074438,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T21:12:35.005Z","updated_at":"2026-04-21T14:02:37.415Z","avatar_url":"https://github.com/TheOpenCMS.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"```ruby\nThis gem is a part of TheOpenCMS project. https://github.com/TheOpenCMS\n```\n\n# CropTool\n\n```json\n{\n  \"name\": \"MyApp\",\n  \"dependencies\": {\n    \"jquery-jcrop\": \"=0.9.13\"\n  }\n}\n```\n\n```sh\nyarn install\n```\n\n**application.html.slim**\n\n```ruby\n= yield :crop_tool\n```\n\n**CSS**\n\n```css\n//= require ptz/reset\n//= require ptz/base\n//= require ptz/framework\n//= require ptz/inputs_buttons/all\n```\n\nand\n\n```css\n//= require crop_tool/crop_tool\n//= require jquery-jcrop/css/jquery.Jcrop\n```\n\nor\n\n```css\n//= require crop_tool/crop_tool\n//= require crop_tool/jcrop/jquery.Jcrop\n```\n\n**JS**\n\n```coffee\n#= require crop_tool/crop_tool\n#= require jquery-jcrop/js/jquery.Jcrop\n```\n\nor\n\n```coffee\n#= require crop_tool/crop_tool\n#= require crop_tool/jcrop/jquery.Jcrop\n```\n\n```coffee\n$ -\u003e\n  do CropTool.init\n```\n\n**routes.rb**\n\n```ruby\n  resources :products do\n    member do\n      patch  :main_image_crop_base\n      patch  :main_image_crop_preview\n      patch  :main_image_rotate\n      delete :main_image_delete\n    end\n  end\n```\n\n**Model**\n\n```ruby\nclass Product \u003c ActiveRecord::Base\n  def main_image_crop_base params\n    crop_params = params[:crop].symbolize_keys\n\n    src  = main_image.path\n    dest = main_image.path :base\n\n    manipulate({ src: src, dest: dest }.merge(crop_params)) do |image, opts|\n      scale = image[:width].to_f / opts[:img_w].to_f\n      image = crop image, opts[:x], opts[:y], opts[:w], opts[:h], scale\n      image = strict_resize image, 270, 210\n      image\n    end\n\n    main_image.url(:base, timestamp: false)\n  end\n\n  def main_image_crop_preview params\n    crop_params = params[:crop].symbolize_keys\n\n    src  = main_image.path\n    dest = main_image.path :preview\n\n    manipulate({ src: src, dest: dest }.merge(crop_params)) do |image, opts|\n      scale = image[:width].to_f / opts[:img_w].to_f\n      image = crop image, opts[:x], opts[:y], opts[:w], opts[:h], scale\n      image = strict_resize image, 100, 100\n      image\n    end\n\n    main_image.url(:preview, timestamp: false)\n  end\n\n  def main_image_rotate\n    return false unless main_image?\n\n    src     = main_image.path\n    base    = main_image.path :base\n    preview = main_image.path :preview\n\n    [src, base, preview].each do |image_path|\n      manipulate({ src: image_path, dest: image_path }) do |image, opts|\n        rotate_right image\n      end\n    end\n  end\n\n  def main_image_destroy!\n    base    = main_image.path(:base).to_s\n    preview = main_image.path(:preview).to_s\n\n    destroy_file [base, preview]\n    main_image.destroy\n\n    save!\n  end\nend\n```\n\n**Controller**\n\n```ruby\nclass ProductsController \u003c ApplicationController\n  before_action :authenticate_user!\n  before_action :set_product\n\n  def main_image_crop_base\n    path = @product.main_image_crop_base(params)\n    render json: { ids: { main_image_base_pic: path } }\n  end\n\n  def main_image_crop_preview\n    path = @product.main_image_crop_preview(params)\n    render json: { ids: { main_image_preview_pic: path } }\n  end\n\n  def main_image_rotate\n    @product.main_image_rotate\n    redirect_to :back\n  end\n\n  def main_image_delete\n    @product.main_image_destroy!\n    redirect_to :back\n  end\nend\n```\n\n**Views**\n\n```slim\n  ruby:\n    crop_data_base = {\n      url:   url_for([:main_image_crop_base, object]),\n      source: object.main_image.url(:original),\n      holder:  { width: 500 },\n      preview: { width: 270, height: 210 },\n      final_size: \"270x210\",\n      callback_handler: \"CropTool.pub_main_image_crop\"\n    }\n\n    crop_data_preview = {\n      url:   url_for([:main_image_crop_preview, object]),\n      source: object.main_image.url(:original),\n      holder:  { width: 500 },\n      preview: { width: 100, height: 100 },\n      final_size: \"100x100\",\n      callback_handler: \"CropTool.pub_main_image_crop\"\n    }\n\n  = link_to \"Crop 270x210\", \"#\", class: \"js_crop_tool\", data: crop_data_base\n  = link_to \"Crop 100x100\", \"#\", class: \"js_crop_tool\", data: crop_data_preview\n  = link_to 'Rotate', [:main_image_rotate, object], method: :patch\n```\n\n### The MIT License (MIT)\n\nCopyright (c) 2014-[Current Year] Ilya N. Zykin (https://github.com/the-teacher)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheopencms%2Fcrop_tool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheopencms%2Fcrop_tool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheopencms%2Fcrop_tool/lists"}