下面的代码可以很好地裁剪图像,这就是我想要的,但对于较大的图像,它也可以工作.有没有办法'缩小图像'
理想的是,我可以在裁剪之前让每张图像的大小大致相同,这样每次都能获得好的效果
代码是
<?php
$image = $_GET['src']; // the image to crop
$dest_image = 'images/cropped_whatever.jpg'; // make sure the directory is writeable
$img = imagecreatetruecolor('200','150');
$org_img = imagecreatefromjpeg($image);
$ims = getimagesize($image);
imagecopy($img,$org_img, 0, 0, 20, 20, 200, 150);
imagejpeg($img,$dest_image,90);
imagedestroy($img);
echo '<img src="'.$dest_image.'" ><p>';
Run Code Online (Sandbox Code Playgroud) 我正在为php cms编写一个模块.在函数(回调)中,我可以访问来自框架代码的对象.
此对象的类型__PHP_Incomplete_Class是因为在会话启动之前不包含所需的头文件.我不能在不破解核心cms代码的情况下包含它.
我想知道是否有可能访问对象属性(转换为数组不起作用).我问这个,因为我可以看到值,var_dump()但使用$object->var我总是得到空值.
我正在尝试creation_time向我的文档添加属性.以下是一个例子:
import datetime
class MyModel(mongoengine.Document):
creation_date = mongo.DateTimeField()
modified_date = mongo.DateTimeField(default=datetime.datetime.now)
Run Code Online (Sandbox Code Playgroud)
Django模型为它们的DateTimeField对象构建了参数,例如add_now,等等,但是MongoEngine不支持这个.
我想知道这样做的最佳方法如下:
m,created = MyModel.objects.get_or_create()
if created:
m.creation_date = datetime.datetime.now()
Run Code Online (Sandbox Code Playgroud)
或者如果有更好,更好的方式.
我需要从gps获得速度和前进.但是我唯一的号码location.getSpeed()是0或有时不可用.我的代码:
String provider = initLocManager();
if (provider == null)
return false;
LocationListener locListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location, interval, startId);
Log.i(getString(R.string.logging_tag), "speed =" + location.getSpeed());
}
public void onProviderDisabled(String provider){
updateWithNewLocation(null, interval, startId);
}
public void onProviderEnabled(String provider) {}
public void onStatusChanged(String provider, int status, Bundle extras) {}
};
_locManager.requestLocationUpdates(provider, interval, DEFAULT_GPS_MIN_DISTANCE, locListener);
private String initLocManager() {
String context = Context.LOCATION_SERVICE;
_locManager = (LocationManager) getSystemService(context);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(true); …Run Code Online (Sandbox Code Playgroud) 如果我有一个日期时间字段,我如何获得仅在某个时间之后创建的记录,完全忽略日期?
它是一个记录表,它告诉人们何时连接并在我们的应用程序中执行某些操作.我想知道人们在晚上5点以后的频率.
(对不起 - 它是SQL Server.但这可能对其他人有用)
我正在制作一个使用SwiftMail扩展程序发送的控制台应用程序.由于我们的策略,我有两个虚拟机,一个用作SMTP中继,另一个用作应用服务器.通过telnet手动发送邮件到继电器工作正常.使用SwiftMail时,它已经坏了.
返回标头,$failure变量中没有返回任何条目send()
回应 getHeaders()->toString()
Message-ID: <1351104631.508838778dc03@swift.generated>
Date: Wed, 24 Oct 2012 14:50:31 -0400
Subject: [YourSite] Feedback
From: noreply@localhost.com
To: sixeightzero@localhost.com
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Run Code Online (Sandbox Code Playgroud)
如果我回应send(),我得到1.
boot.php
$app->register(new Silex\Provider\SwiftmailerServiceProvider(), array(
'swiftmailer.options' => array(
'host' => 'ip.host.relay',
'port' => 25,
'encryption' => null,
'auth_mode' => null
),
));
Run Code Online (Sandbox Code Playgroud)
app.php
$message = \Swift_Message::newInstance( )
->setSubject('[YourSite] Feedback')
->setFrom(array('noreply@localhost.com'))
->setTo(array('sixeightzero@localhost.com'))
->setBody("Message!");
$app['mailer']->send($message, $failures);
Run Code Online (Sandbox Code Playgroud)
当我在应用服务器上运行TCP转储并运行脚本时,没有建立任何SMTP连接,并且没有抛出任何错误.
有没有遇到过这个?由于我们的应用程序要求,我不想使用sendmail或邮件,而是使用SMTP.
我能够在imageview中通过XMPP显示头像.
但是当我删除应用程序并从那时起重新启动它时,我没有通过方法获取imagedata
- (NSData *)photoDataForJID:(XMPPJID *)jid
Run Code Online (Sandbox Code Playgroud) 我将我的活动设置为默认启动器,以拦截主页按钮点击,如下所示:
<activity
android:name=".ExampleActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
当我的活动ExampleActivity启动时,如果我点击该home键,我会被提示选择.如果我选择将此设为我的默认设置并选择我的活动,我会陷入我的活动中.
问题是,当我离开活动时,我尝试从默认启动器中删除我的活动,但是不成功.
我试过了:
ComponentName componentName = new ComponentName(
"com.example.exampleactivity",
"com.example.exampleactivity.class");
pm.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);
Run Code Online (Sandbox Code Playgroud)
和:
PackageManager pm = getActivity().getPackageManager();
ComponentName name = new ComponentName(this, "com.example.exampleactivity.class");
pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
Run Code Online (Sandbox Code Playgroud)
但是我的名字home永远不会被删除.
有没有人有办法解决上述问题?
我只是不想将主页按钮作为特定活动的默认设置,而不是我的整个应用程序.当我离开活动时,应将其删除并恢复为默认值.
android android-intent android-package-managers android-launcher
从HTML表单中提取输入值时遇到一些问题.据我所知,我的代码没有任何问题,但我找不到问题所在.
<?php
error_reporting(E_ALL );
ini_set('display_errors', 1);
$t =<<<D
<form id="frm-send" method="post" action="index.php" >
<input type="text" name="data[postusername]" id="postusername" value="user" />
<input type="checkbox" name="data[save]" id="data[save]" value="1" />
<input type="hidden" name="secret" id="secret" value="0d35635c0cb11760789de6c4fe35e046311f724b" />
<input type="submit" name="btnSubmit" id="btnSubmit" value="Send" />
<input type="hidden" name="data[checkgetrequest]" value="true" id="data[checkgetrequest]" />
<input type="hidden" name="frm-id" value="13448477965028bfb44222d" id="frm-id" />
</form>
<input type="text" id="getfocus_txt_13448477965028bfb44222d" name="getfocus_txt_13448477965028bfb44222d" />
D;
$dom = new domDocument;
$dom->loadHTML($t);
$dom->preserveWhiteSpace = true;
$frmid = $dom->getElementById('frm-id') ;
echo $frmid->getAttribute('value');
?>
Run Code Online (Sandbox Code Playgroud)
它显示了一个错误:
Fatal error: Call to a member function getAttribute() …Run Code Online (Sandbox Code Playgroud) 我有一个基于FTDI芯片的USB设备.有时,它的驱动程序卡住了.
在linux下,没有问题 - 设备自动断开连接,并通过默认内核重新连接,只有问题是设备名称已更改 - 可以通过udev规则修复.
在Windows下,当它卡住时,应用程序的线程read()或write()当时完全挂起.它不能被杀死TerminateThread,也不能被杀死KillProcess.
杀死应用程序的唯一方法是物理断开USB设备.
有没有办法以编程方式发出设备重新连接,这将删除驱动程序的死锁并允许重新打开端口并继续工作?
如果需要,管理权利申请可以有.